Reputation: 325
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".
Upvotes: 1
Views: 1045
Reputation: 76700
Jupyter only needs to be install in a single location - either a Conda env or at the system-level.
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. Always launch jupyter notebook
from the env with Jupyter and the others will be available automatically.
If Jupyter is installed at a system level, one must manually register the Conda envs one wishes to use as kernels:
conda activate my_env
conda install ipykernel
python -m ipykernel install --user --name my_env_name
Then launch Jupyter from anywhere.
Upvotes: 1