2.1 安装 Python 版本
① 首先打开 Anaconda 的 Prompt 终端,输入 jupyter kernelspec list,查看已经安装的 python 版本。如下图所示,只有 Anaconda 自带的 python3。
② 输入 conda create --name py3.6.3 python=3.6.3 命令,输入 [y]/n 时输入 y,创建 py3.6.3 虚拟环境,它会安装 python3.6.3 到 anaconda3 的 env 目录下。
③ 首先确保目前盘和要进入的盘一样,输入 cd D:\11_Anaconda\envs\py3.6.3\Scripts 命令,进入 py3.6.3 目录下的 Scripts 文件夹下。
④ 输入 conda activate py3.6.3 激活 py3.6.3环境后,再输入 pip install ipykernel 命令,会在 script 目录下会生成一系列工具,如下图所示。( 注意:当 pip install ipykernel 时,不能挂 VNP。)
⑤ 将 Anaconda 文件夹下的 share/jupyter/kernels 文件夹中已经存在的项目复制一份,重命名为 python3.6.3。
⑥ 打开文件夹中 json 文件,将 Python 3 改为 Python 3.6.3,如下图所示。
⑦ 再次打开 Anaconda 终端,输入 jupyter kernelspec list,可以查看到已成功安上 Python3.6.3 的虚拟环境。
⑧ 再次打开 Jupyter notebook,New 里面有 Python3.6.3 选项。
⑨ 在 Jupyter notebook 中,用 python 代码打印 python 版本。
import sys
print(sys.version)
结果:
3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 15:10:56) [MSC v.1900 64 bit (AMD64)]
2.2 安装 d2l 库
! pip install d2l
结果:
Requirement already satisfied: d2l in d:\11_anaconda\envs\py3.6.3\lib\site-packages (0.17.0) Requirement already satisfied: requests in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from d2l) (2.27.1) Requirement already satisfied: numpy in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from d2l) (1.19.5) Requirement already satisfied: pandas in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from d2l) (1.1.5) Requirement already satisfied: jupyter in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from d2l) (1.0.0) Requirement already satisfied: matplotlib in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from d2l) (3.3.4) Requirement already satisfied: ipywidgets in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (7.7.0) Requirement already satisfied: ipykernel in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (5.5.6) Requirement already satisfied: nbconvert in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (6.0.7) Requirement already satisfied: jupyter-console in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (6.4.3) Requirement already satisfied: notebook in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (6.4.10) Requirement already satisfied: qtconsole in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter->d2l) (5.2.2) Requirement already satisfied: ipython-genutils in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipykernel->jupyter->d2l) (0.2.0) Requirement already satisfied: tornado>=4.2 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipykernel->jupyter->d2l) (6.1) Requirement already satisfied: jupyter-client in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipykernel->jupyter->d2l) (7.1.2) Requirement already satisfied: ipython>=5.0.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipykernel->jupyter->d2l) (7.16.3) Requirement already satisfied: traitlets>=4.1.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipykernel->jupyter->d2l) (4.3.3) Requirement already satisfied: colorama in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (0.4.4) Requirement already satisfied: decorator in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (5.1.1) Requirement already satisfied: pygments in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (2.11.2) Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (3.0.26) Requirement already satisfied: backcall in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (0.2.0) Requirement already satisfied: setuptools>=18.5 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (58.0.4) Requirement already satisfied: pickleshare in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (0.7.5) Requirement already satisfied: jedi<=0.17.2,>=0.10 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipython>=5.0.0->ipykernel->jupyter->d2l) (0.17.2) Requirement already satisfied: parso<0.8.0,>=0.7.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jedi<=0.17.2,>=0.10->ipython>=5.0.0->ipykernel->jupyter->d2l) (0.7.1) Requirement already satisfied: wcwidth in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->jupyter->d2l) (0.2.5) Requirement already satisfied: six in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from traitlets>=4.1.0->ipykernel->jupyter->d2l) (1.16.0) Requirement already satisfied: nbformat>=4.2.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipywidgets->jupyter->d2l) (5.1.3) Requirement already satisfied: widgetsnbextension~=3.6.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipywidgets->jupyter->d2l) (3.6.0) Requirement already satisfied: jupyterlab-widgets>=1.0.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from ipywidgets->jupyter->d2l) (1.1.0) Requirement already satisfied: jupyter-core in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbformat>=4.2.0->ipywidgets->jupyter->d2l) (4.9.1) Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbformat>=4.2.0->ipywidgets->jupyter->d2l) (3.2.0) Requirement already satisfied: attrs>=17.4.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter->d2l) (21.4.0) Requirement already satisfied: pyrsistent>=0.14.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter->d2l) (0.18.0) Requirement already satisfied: importlib-metadata in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter->d2l) (4.8.3) Requirement already satisfied: terminado>=0.8.3 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (0.12.1) Requirement already satisfied: argon2-cffi in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (21.3.0) Requirement already satisfied: pyzmq>=17 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (22.3.0) Requirement already satisfied: Send2Trash>=1.8.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (1.8.0) Requirement already satisfied: prometheus-client in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (0.13.1) Requirement already satisfied: nest-asyncio>=1.5 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (1.5.4) Requirement already satisfied: jinja2 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from notebook->jupyter->d2l) (3.0.3) Requirement already satisfied: python-dateutil>=2.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter-client->ipykernel->jupyter->d2l) (2.8.2) Requirement already satisfied: entrypoints in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter-client->ipykernel->jupyter->d2l) (0.4) Requirement already satisfied: pywin32>=1.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jupyter-core->nbformat>=4.2.0->ipywidgets->jupyter->d2l) (303) Requirement already satisfied: mistune<2,>=0.8.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (0.8.4) Requirement already satisfied: defusedxml in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (0.7.1) Requirement already satisfied: jupyterlab-pygments in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (0.1.2) Requirement already satisfied: bleach in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (4.1.0) Requirement already satisfied: testpath in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (0.6.0) Requirement already satisfied: pandocfilters>=1.4.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (1.5.0) Requirement already satisfied: nbclient<0.6.0,>=0.5.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbconvert->jupyter->d2l) (0.5.9) Requirement already satisfied: MarkupSafe>=2.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from jinja2->notebook->jupyter->d2l) (2.0.1) Requirement already satisfied: async-generator in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from nbclient<0.6.0,>=0.5.0->nbconvert->jupyter->d2l) (1.10) Requirement already satisfied: pywinpty>=1.1.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from terminado>=0.8.3->notebook->jupyter->d2l) (1.1.6) Requirement already satisfied: dataclasses in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from argon2-cffi->notebook->jupyter->d2l) (0.8) Requirement already satisfied: argon2-cffi-bindings in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from argon2-cffi->notebook->jupyter->d2l) (21.2.0) Requirement already satisfied: typing-extensions in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from argon2-cffi->notebook->jupyter->d2l) (3.10.0.2) Requirement already satisfied: cffi>=1.0.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from argon2-cffi-bindings->argon2-cffi->notebook->jupyter->d2l) (1.15.0) Requirement already satisfied: pycparser in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->notebook->jupyter->d2l) (2.21) Requirement already satisfied: packaging in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from bleach->nbconvert->jupyter->d2l) (21.3) Requirement already satisfied: webencodings in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from bleach->nbconvert->jupyter->d2l) (0.5.1) Requirement already satisfied: zipp>=0.5 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from importlib-metadata->jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter->d2l) (3.6.0) Requirement already satisfied: cycler>=0.10 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from matplotlib->d2l) (0.11.0) Requirement already satisfied: kiwisolver>=1.0.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from matplotlib->d2l) (1.3.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from matplotlib->d2l) (3.0.7) Requirement already satisfied: pillow>=6.2.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from matplotlib->d2l) (8.4.0) Requirement already satisfied: pytz>=2017.2 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from pandas->d2l) (2021.3) Requirement already satisfied: qtpy in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from qtconsole->jupyter->d2l) (2.0.1) Requirement already satisfied: idna<4,>=2.5 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from requests->d2l) (3.3) Requirement already satisfied: charset-normalizer~=2.0.0 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from requests->d2l) (2.0.12) Requirement already satisfied: certifi>=2017.4.17 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from requests->d2l) (2021.5.30) Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\11_anaconda\envs\py3.6.3\lib\site-packages (from requests->d2l) (1.26.9) Note: you may need to restart the kernel to use updated packages.