今天在使用Python的时候,使用Anaconda创建了一个虚拟环境,在Jupyter Notebook中也激活了这个虚拟环境,而且在这个环境下也安装好了相应的包
但怎么实验,也无法在Jupyter Notebook中成功import新包,报错显示No module xxx found。
实验了各种方法均不成功,后按照下文的方式重新配置一个新的虚拟环境后,再次安装新包成功,特此记录一下方法。
文章的链接和具体内容如下:
在Windows下,为Jupyter创建新的kernel
1.创建环境
- 打开Anaconda Prompt
- 输入以下代码创建环境
(D:\Users\拾夕\Anaconda3) C:\Users\拾夕>conda create -n KernelForJupyter python=3.6
- 得到以下结果
The following NEW packages will be INSTALLED: certifi: 2016.2.28-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free pip: 9.0.1-py36_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free python: 3.6.2-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free setuptools: 36.4.0-py36_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free vc: 14-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free vs2015_runtime: 14.0.25420-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free wheel: 0.29.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free wincertstore: 0.2-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free Proceed ([y]/n)? y Linking packages ... [ COMPLETE ]|##################################################| 100% # # To activate this environment, use: # > activate KernelForJupyter # # To deactivate this environment, use: # > deactivate KernelForJupyter # # * for power-users using bash, you must source #
2.激活环境以及安装必要的包
- 输入以下代码激活环境
(D:\Users\拾夕\Anaconda3) C:\Users\拾夕> activate KernelForJupyter
- 安装 ipykernel
(KernelForJupyter) C:\Users\拾夕>conda install ipykernel
3.创建新的kernel
- 输入以下代码创建新的kernel
(KernelForJupyter) C:\Users\拾夕>python -m ipykernel install --name NewKernel Installed kernelspec NewKernel in C:\ProgramData\jupyter\kernels\newkernel
4.Jupyter其他操作
- 我们通过以下代码查看juypter kernel的其他命令
(KernelForJupyter) C:\Users\拾夕>jupyter kernelspec --help Manage Jupyter kernel specifications. Subcommands ----------- Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on using subcommand 'cmd', do: `jupyter kernelspec cmd -h`. list List installed kernel specifications. install Install a kernel specification directory. uninstall Alias for remove remove Remove one or more Jupyter kernelspecs by name. install-self [DEPRECATED] Install the IPython kernel spec directory for this Python
- 例如我们可以通过以下指令查看当前环境下的kernel
(KernelForJupyter) C:\Users\拾夕>jupyter kernelspec list
Available kernels:
python3 D:\Users\拾夕\Anaconda3\envs\KernelForJupyter\share\jupyter\kernels\python3
newkernel C:\ProgramData\jupyter\kernels\newkernel
文章评论