anar
anar

Reputation: 543

ModuleNotFoundError in Jupyter Lab for package pycwt

I have a conda environment where I have installed the wavelet package pycwt using:

conda install -n myenv -c conda-forge pycwt

as prescribed in the Anaconda cloud.

On my terminal, the command import pycwt works just fine. When I open a notebook on Jupyter Lab (within the virtual environment), running

import pycwt

yields

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-501c582ee37d> in <module>
----> 1 import pycwt

ModuleNotFoundError: No module named 'pycwt'

The same command works fine when I run it on a terminal within Jupyter Lab. Other packages I have installed in the virtual environment run just fine in both the notebook and on the terminal.

It looks like there are similar questions on StackOverflow here and here but neither have been answered yet.

Upvotes: 4

Views: 5478

Answers (1)

anar
anar

Reputation: 543

I figured it out: It looks like my notebook in Jupyter Lab was running the base kernel and not the kernel of the virtual environment. I typed

import sys
sys.executable

into my notebook and got the result

'/anaconda3/bin/python'

instead of the desired

'/anaconda3/envs/myenv/bin/python'

I solved it by following the instructions in the iPython documentation. In summary, I needed to install a new iPython kernel for my new environment. Run:

conda install -n myenv ipython
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

Then, to run Jupyter Lab in the new environment:

conda activate myenv
jupyter lab

And I was able to select the kernel "Python (myenv)" when I opened a new notebook (also in the top right of an existing notebook).

Upvotes: 3

Related Questions