Jupyter Lab 中的 pycwt 包出现 ModuleNotFoundError

2024-02-08

我有一个conda环境,我已经安装了wavelet包pycwt https://pypi.org/project/pycwt/ using:

conda install -n myenv -c conda-forge pycwt

按照规定蟒蛇云 https://anaconda.org/conda-forge/pycwt.

在我的终端上,命令import pycwt工作得很好。当我打开一个notebook在 Jupyter Lab 上(在虚拟环境中),运行

import pycwt

yields

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

ModuleNotFoundError: No module named 'pycwt'

当我在终端上运行相同的命令时,它工作正常Jupyter 实验室内。我在虚拟环境中安装的其他软件包在笔记本电脑和终端上都运行良好。

StackOverflow 上好像也有类似的问题here https://stackoverflow.com/questions/51433227/jupyter-lab-installing-importing-packages and here https://stackoverflow.com/questions/45513938/jupyter-notebook-modulenotfound-error-for-a-module-that-is-installed但都还没有得到答复。


我发现:看起来我在 Jupyter Lab 中的笔记本正在运行基本内核,而不是虚拟环境的内核。我输入了

import sys
sys.executable

进入我的笔记本并得到结果

'/anaconda3/bin/python'

而不是想要的

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

我按照中的说明解决了这个问题iPython 文档 https://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments。总之,我需要为我的新环境安装新的 iPython 内核。跑步:

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

然后,在新环境中运行 Jupyter Lab:

conda activate myenv
jupyter lab

当我打开一个新笔记本(也在现有笔记本的右上角)时,我能够选择内核“Python (myenv)”。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jupyter Lab 中的 pycwt 包出现 ModuleNotFoundError 的相关文章

随机推荐