为了测试已安装软件包的兼容性,我创建了多个conda环境。我conda create -n test02 --clone test01
用来创建环境test02作为test01的克隆。我激活test02,安装新软件包并启动python实例,从该实例中导入新软件包没有问题。当我启动jupyter笔记本电脑或qtconsole并尝试导入新安装的程序包并获得导入错误:没有名为“ xxx”的模块时,就会出现问题。我做了一个sys.executable
,发现jupyter从旧环境(test01)运行python,我从中克隆了新环境。为什么会这样呢?我可以在某个地方的配置文件中更改它吗?在哪里可以找到此文件?
编辑:更多信息
jupyter --paths
这两个环境在同一环境目录中共享配置和数据的路径条目
(test01) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
(test01) PS C:\Users\Aka> conda activate test02
(test02) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
edit2:我忘了提到我使用pip安装了Jupyter。
重现我所做的问题:
conda create -n env1
conda activate env1
pip install jupyter
jupyter --paths
配置:
C:\ Users \ Aka.jupyter
c:\ users \ aka \ miniconda3 \ envs \ env1 \ etc \ jupyter
C:\ ProgramData \ jupyter
数据:
C:\ Users \ Aka \ AppData \ Roaming \ jupyter
c:\ users \ aka \ miniconda3 \ envs \ env1 \ share \ jupyter
C:\ ProgramData \ jupyter
运行时:
C:\ Users \ Aka \ AppData \ Roaming \ jupyter \ runtime
conda create --clone env1 -n env2
conda activate env2
jupyter --paths
配置:
C:\ Users \ Aka.jupyter
c:\ users \ aka \ miniconda3 \ envs \ env1 \ etc \ jupyter
C:\ ProgramData \ jupyter
数据:
C:\ Users \ Aka \ AppData \ Roaming \ jupyter
c:\ users \ aka \ miniconda3 \ envs \ env1 \ share \ jupyter
C:\ ProgramData \ jupyter
运行时:
C:\ Users \ Aka \ AppData \ Roaming \ jupyter \ runtime
如果我要将带有conda的jupyter安装到全新的环境中,然后克隆该环境,jupyter的行为将与预期的一样。注意:我使用pip安装了jupyter,因为我使用的是python 3.5,因为我需要其他软件包,因此在我的环境中使用conda安装jupyter时会不断破坏它。我伸出手去向conda-forge寻求帮助,但他们说“对不起,我们不支持python 3.5”。
Jupyter只需要安装在一个位置即可-Conda env或系统级。
要将其他env用作内核,需要使用Jupyter将其安装nb_conda_kernels
在env中,以及ipykernel
您希望用作内核的任何env中。始终jupyter notebook
使用Jupyter从环境启动,其他将自动可用。
如果Jupyter是在系统级别安装的,则必须手动注册一个希望用作内核的Conda env:
conda activate my_env
conda install ipykernel
python -m ipykernel install --user --name my_env_name
然后从任何地方启动Jupyter。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句