Anaconda安裝配置Python虛擬環境后使用JupyterNoteBook導入新包失敗的解決方法

2024年1月10日 1843點熱度 0人點贊 0條評論

今天在使用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
  • 然后就可以在Jupyter中使用了

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

領測老賀

領測軟件測試網站長,ISTQB認證高級培訓師,TMMi認證咨詢師。深耕軟件測試行業20余年,領測老賀聊軟件測試制造者。

文章評論

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97