1

I have created multiple conda environments in order to test compatibility of installed packages. I use conda create -n test02 --clone test01 to create environment test02 as a clone of test01. I activate test02, install new packages and start instance of python from which I import new packages with no problem. 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'. I do a sys.executable and see that jupyter is running python from the old environment (test01) I cloned the new one from. 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

(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.

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\miniconda3\envs\env1\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\env1\share\jupyter
C:\ProgramData\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\miniconda3\envs\env1\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\env1\share\jupyter
C:\ProgramData\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. 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. I reached out to conda-forge for help but they said "sorry, we don't support python 3.5".

4

1 回答 1

1

Jupyter 只需要安装在一个位置——无论是 Conda 环境还是系统级别。

安装在 Conda 环境中的 Jupyter

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

康达外的 Jupyter

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

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

然后从任何地方启动 Jupyter。

于 2020-01-22T22:53:41.333 回答