繁体   English   中英

Jupyter 和 conda:克隆环境时出错

[英]Jupyter and conda: error when cloning environment

我创建了多个 conda 环境以测试已安装软件包的兼容性。 我使用conda create -n test02 --clone test01创建环境 test02 作为 test01 的克隆。 我激活 test02,安装新包并启动 python 实例,从中导入新包没有问题。 当我启动 jupyter notebook 或 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

编辑 2:我忘了提到我使用 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 环境或系统级别。

安装在 Conda 环境中的 Jupyter

要将其他环境用作内核,需要使用nb_conda_kernels在环境中安装 nb_conda_kernels,并在您希望用作内核的任何ipykernel中安装nb_conda_kernels 始终使用jupyter notebook从 env 启动jupyter notebook ,其他的将自动可用。

Conda 外的 Jupyter

如果 Jupyter 安装在系统级别,则必须手动注册希望用作内核的 Conda 环境:

conda activate my_env
conda install ipykernel
python -m ipykernel install --user --name my_env_name

然后从任何地方启动 Jupyter。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM