简体   繁体   English

Jupyter 和 conda:克隆环境时出错

[英]Jupyter and conda: error when cloning environment

I have created multiple conda environments in order to test compatibility of installed packages.我创建了多个 conda 环境以测试已安装软件包的兼容性。 I use conda create -n test02 --clone test01 to create environment test02 as a clone of test01.我使用conda create -n test02 --clone test01创建环境 test02 作为 test01 的克隆。 I activate test02, install new packages and start instance of python from which I import new packages with no problem.我激活 test02,安装新包并启动 python 实例,从中导入新包没有问题。 The problem arises when I launch jupyter notebook or qtconsole and try to import newly installed package and get import error: no module named 'xxx'.当我启动 jupyter notebook 或 qtconsole 并尝试导入新安装的包并出现导入错误时出现问题:没有名为“xxx”的模块。 I do a sys.executable and see that jupyter is running python from the old environment (test01) I cloned the new one from.我做了一个sys.executable并看到 jupyter 正在从旧环境(test01)运行 python 我从中克隆了新环境。 Why is this happening?为什么会这样? Can I change it in config file somewhere and where might I find this file?我可以在某个地方的配置文件中更改它吗?在哪里可以找到这个文件?

edit: more info编辑:更多信息

jupyter --paths for both environments share path entry for config and data in the same environment directory 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: I forgot to mention that I installed Jupyter using pip.编辑 2:我忘了提到我使用 pip 安装了 Jupyter。

to recreate the problem I did:重现我所做的问题:

conda create -n env1
conda activate env1
pip install jupyter
jupyter --paths

config:配置:
C:\\Users\\Aka.jupyter C:\\Users\\Aka.jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter
C:\\ProgramData\\jupyter C:\\ProgramData\\jupyter
data:数据:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter C:\\Users\\Aka\\AppData\\Roaming\\jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter
C:\\ProgramData\\jupyter C:\\ProgramData\\jupyter
runtime:运行:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime

conda create --clone env1 -n env2
conda activate env2
jupyter --paths

config:配置:
C:\\Users\\Aka.jupyter C:\\Users\\Aka.jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter
C:\\ProgramData\\jupyter C:\\ProgramData\\jupyter
data:数据:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter C:\\Users\\Aka\\AppData\\Roaming\\jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter
C:\\ProgramData\\jupyter C:\\ProgramData\\jupyter
runtime:运行:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime

If I were to install jupyter with conda into a brand new environment and then clone the environment, jupyter behaves as expected.如果我将带有 conda 的 jupyter 安装到一个全新的环境中,然后克隆该环境,则 jupyter 会按预期运行。 Note: I installed jupyter with pip because I am using python 3.5 because of other packages I need and installing jupyter with conda in my environments kept breaking it.注意:我使用 pip 安装了 jupyter,因为我使用的是 python 3.5,因为我需要其他软件包,并且在我的环境中使用 conda 安装 jupyter 不断破坏它。 I reached out to conda-forge for help but they said "sorry, we don't support python 3.5".我向 conda-forge 寻求帮助,但他们说“对不起,我们不支持 python 3.5”。

Jupyter only needs to be install in a single location - either a Conda env or at the system-level. Jupyter 只需要安装在一个位置 - Conda 环境或系统级别。

Jupyter installed in Conda env安装在 Conda 环境中的 Jupyter

To use other envs as kernels, one needs to install nb_conda_kernels in the env with Jupyter, and ipykernel in any env you wish to use as a kernel.要将其他环境用作内核,需要使用nb_conda_kernels在环境中安装 nb_conda_kernels,并在您希望用作内核的任何ipykernel中安装nb_conda_kernels Always launch jupyter notebook from the env with Jupyter and the others will be available automatically.始终使用jupyter notebook从 env 启动jupyter notebook ,其他的将自动可用。

Jupyter outside Conda Conda 外的 Jupyter

If Jupyter is installed at a system level, one must manually register the Conda envs one wishes to use as kernels:如果 Jupyter 安装在系统级别,则必须手动注册希望用作内核的 Conda 环境:

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

Then launch Jupyter from anywhere.然后从任何地方启动 Jupyter。

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

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