ModuleNotFoundError in Jupyter Lab for package pycwt

≡放荡痞女 提交于 2020-12-06 06:44:09

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/56866495/modulenotfounderror-in-jupyter-lab-for-package-pycwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!