jupyter notebook reports an error using conda virtual environment

Keywords: Python jupyter IDE

introduce

First use Anaconda to create a virtual environment named pt37, and then want to open jupyter in this virtual environment.

Follow other online tutorials and use conda install nb_conda and python -m ipykernel install --name {your virtual environment name, such as QQ} -- display name {the name you want to display} did not find the created virtual environment in their own Jupiter

In addition, there will be various error reporting problems:

  • conda install nb_ Problems during installation of CONDA:
    (the screenshot cannot be found. Please quote someone else's screenshot)
  • Problems when installing using python -m ipykernel install --name {your virtual environment name, such as QQ} -- display name {the name you want to display}
(pt37) C:\Users\19631>python -m ipykernel install --user --name pt37 --display-name pt37
Installed kernelspec pt37 in C:\Users\19631\AppData\Roaming\jupyter\kernels\pt37

(pt37) C:\Users\19631>jupyter notebook
Cannot open D:\Anaconda\envs\pt37\Scripts\jupyter-notebook-script.py

So I want to install another jupyter directly in the virtual environment

jupyter and ipykernel have been installed in the virtual environment of pt37
You can directly use conda install jupyter and CONDA install ipykener to install. If an error is reported in jupyter installation, you can use pip install jupyter to install.

When I use conda for installation, the following errors will appear:

Error message:

ChecksumMismatchError: Conda detected a mismatch between the expected content and downloaded content
for url 'http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch/jupyter_console-6.4.0-pyhd3eb1b0_0.conda'.
  download saved to: D:\Anaconda\pkgs\jupyter_console-6.4.0-pyhd3eb1b0_0.conda
  expected sha256: d925edd3ae53456716abcd422b73ecedc610f78f17e53f3feb693f98e75918fc
  actual sha256: 53dffa149d7cfc4c9cc5638cbbbec1c1aabd84b0781299c27f5e1b382da46ee0

ChecksumMismatchError: Conda detected a mismatch between the expected content and downloaded content
for url 'http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/notebook-6.4.6-py37haa95532_0.conda'.
  download saved to: D:\Anaconda\pkgs\notebook-6.4.6-py37haa95532_0.conda
  expected sha256: 510268efd0828bba6afe4241a15f8a0287469e37d5d03d70511f4dc00eeabf0a
  actual sha256: 53dffa149d7cfc4c9cc5638cbbbec1c1aabd84b0781299c27f5e1b382da46ee0


Therefore, using pip for installation will be successful

Installation succeeded. The environment contains jupyter

Further major issues

So can you happily open jupyter?? Ah, no, there is still a problem, and the problem is that I installed Nb in the main environment of CONDA_ The problem with CONDA is that "nb_conda_kernels.Conda cannot be imported"
This problem makes my jupyter unable to be used directly, and it cannot be opened either in shortcut or terminal mode.
However, at the instigation of my friends, I unloaded conda and reinstalled it to make everything look like the original. Then I thought of using jupyter in the virtual environment, and I can continue to use jupyter later

Error message

[C 09:52:54.885 NotebookApp] Bad config encountered during initialization: The 'kernel_spec_manager_class' trait of <notebook.notebookapp.NotebookApp object at 0x000002B09C38E808> instance must be a type, but 'nb_conda_kernels.CondaKernelSpecManager' could not be imported


Solution
I installed jupyter in the virtual environment, but I couldn't open it, so I tried whether the jupyter in the previous main environment can still be used. After all, I installed two jupyters

WOW!!! Can use, thank God!!!
Then look at the kernel

It succeeded!!!

Although I don't know how I succeeded, I stepped on a lot of pits along the way, including unloading and reloading, so I simply write down the problems I encountered, hoping to help you. I've been groping. I hope you can communicate with me if you have any problems!

Posted by mlavwilson on Fri, 26 Nov 2021 06:50:05 -0800