diff --git a/examples/user_guide/k230_simulate-EN.ipynb b/examples/user_guide/k230_simulate-EN.ipynb index 601864dd73..309f8cd830 100644 --- a/examples/user_guide/k230_simulate-EN.ipynb +++ b/examples/user_guide/k230_simulate-EN.ipynb @@ -36,25 +36,36 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "id": "8b32a0b5-90b0-4bc7-8448-2a544b7d06e9", + "attachments": {}, + "cell_type": "markdown", + "id": "a17fa3cf", "metadata": {}, - "outputs": [], "source": [ - "# ubuntu\n", - "%env PATH=$PATH:/usr/local/lib/python3.7/site-packages" + "## auto set enviroment" ] }, { - "attachments": {}, - "cell_type": "markdown", - "id": "960b50d1-1990-4b1c-b8be-0a9f04fb6907", + "cell_type": "code", + "execution_count": null, + "id": "7cdadfc6", "metadata": {}, + "outputs": [], "source": [ - "* In Windows OS\n", - "> You need to add the path where nncase packages were installed into `PATH` environment variable.\n", - "After it, you need to restart your `CMD`. " + "import os\n", + "import sys\n", + "import subprocess\n", + "\n", + "result = subprocess.run([\"pip\", \"show\", \"nncase\"], capture_output=True)\n", + "\n", + "if sys.platform == \"win32\":\n", + " location = result.stdout.decode().split(\"\\r\\n\")[7].split(\": \")[1]\n", + "else:\n", + " location = result.stdout.decode().split(\"\\n\")[7].split(\": \")[1]\n", + "\n", + "if \"PATH\" in os.environ:\n", + " os.environ[\"PATH\"] += os.pathsep + location\n", + "else:\n", + " os.environ[\"PATH\"] = location" ] }, { diff --git a/examples/user_guide/k230_simulate-ZH.ipynb b/examples/user_guide/k230_simulate-ZH.ipynb index ec378c0312..e5a9a55d86 100644 --- a/examples/user_guide/k230_simulate-ZH.ipynb +++ b/examples/user_guide/k230_simulate-ZH.ipynb @@ -36,24 +36,36 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "id": "8b32a0b5-90b0-4bc7-8448-2a544b7d06e9", + "attachments": {}, + "cell_type": "markdown", + "id": "d8d2a6f0", "metadata": {}, - "outputs": [], "source": [ - "# ubuntu\n", - "%env PATH=$PATH:/usr/local/lib/python3.7/site-packages" + "## 自动设置环境变量" ] }, { - "attachments": {}, - "cell_type": "markdown", - "id": "960b50d1-1990-4b1c-b8be-0a9f04fb6907", + "cell_type": "code", + "execution_count": null, + "id": "8b32a0b5-90b0-4bc7-8448-2a544b7d06e9", "metadata": {}, + "outputs": [], "source": [ - "* Windows平台\n", - "> 需要将nncase的安装路径加入到`PATH`环境变量中,并且重启你的`CMD`。" + "import os\n", + "import sys\n", + "import subprocess\n", + "\n", + "result = subprocess.run([\"pip\", \"show\", \"nncase\"], capture_output=True)\n", + "\n", + "if sys.platform == \"win32\":\n", + " location = result.stdout.decode().split(\"\\r\\n\")[7].split(\": \")[1]\n", + "else:\n", + " location = result.stdout.decode().split(\"\\n\")[7].split(\": \")[1]\n", + "\n", + "if \"PATH\" in os.environ:\n", + " os.environ[\"PATH\"] += os.pathsep + location\n", + "else:\n", + " os.environ[\"PATH\"] = location\n" ] }, {