今天在使用Python的時(shí)候,使用Anaconda創(chuàng )建了一個(gè)虛擬環(huán)境,在Jupyter Notebook中也激活了這個(gè)虛擬環(huán)境,而且在這個(gè)環(huán)境下也安裝好了相應的包
但怎么實(shí)驗,也無(wú)法在Jupyter Notebook中成功import新包,報錯顯示No module xxx found。
實(shí)驗了各種方法均不成功,后按照下文的方式重新配置一個(gè)新的虛擬環(huán)境后,再次安裝新包成功,特此記錄一下方法。
文章的鏈接和具體內容如下:
在Windows下,為Jupyter創(chuàng )建新的kernel
1.創(chuàng )建環(huán)境
- 打開(kāi)Anaconda Prompt
- 輸入以下代碼創(chuàng )建環(huán)境
(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.激活環(huán)境以及安裝必要的包
- 輸入以下代碼激活環(huán)境
(D:\Users\拾夕\Anaconda3) C:\Users\拾夕> activate KernelForJupyter
- 安裝 ipykernel
(KernelForJupyter) C:\Users\拾夕>conda install ipykernel
3.創(chuàng )建新的kernel
- 輸入以下代碼創(chuàng )建新的kernel
(KernelForJupyter) C:\Users\拾夕>python -m ipykernel install --name NewKernel Installed kernelspec NewKernel in C:\ProgramData\jupyter\kernels\newkernel
4.Jupyter其他操作
- 我們通過(guò)以下代碼查看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
- 例如我們可以通過(guò)以下指令查看當前環(huán)境下的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
文章評論