conda环境下jupyter notebook无法连接到内核的问题解决

利用anaconda安装python环境,使用jupyter notebook进行编译,在导入package时就出现一大堆的报错

报错信息:

conda环境下jupyter notebook无法连接到内核的问题解决_第1张图片 

报错中特别强调让我们查看官方文档,描述如下:

Activating environments is essential to making the software in the environments work well. Activation entails two primary functions: adding entries to PATH for the environment and running any activation scripts that the environment may contain. These activation scripts are how packages can set arbitrary environment variables that may be necessary for their operation. You can also use the config API to set environment variables.

When installing Anaconda, you have the option to “Add Anaconda to my PATH environment variable.” This is not recommended because the add to PATH option appends Anaconda to PATH. When the installer appends to PATH, it does not call the activation scripts.

On Windows, PATH is composed of two parts, the system PATH and the user PATH. The system PATH always comes first. When you install Anaconda for Just Me, we add it to the user PATH. When you install for All Users, we add it to the system PATH. In the former case, you can end up with system PATH values taking precedence over our entries. In the latter case, you do not. We do not recommend multi-user installs.

Activation prepends to PATH. This only takes effect when you have the environment active so it is local to a terminal session, not global.

To activate an environment: 
conda activate myenv

大致意思是,出现这种情况的原因是没有事先激活conda 环境,需要在命令行(powershell不行)中激活。

 myenv是自己定义的环境名称。

仍然需要注意的一点是,acivate操作只针对当前目录的文件夹。如果在其他的地方打开jupyter notebook,也是无效的。

因此,要打开一个ipynb文件的操作最好是:

1.打开命令行

2.使用cd命令切换在文件所在目录

3.输入conda activate myenv(自己的环境名字)激活环境

4.输入jupyter notebook

便可以成功打开并完美编译了!

你可能感兴趣的:(python)