[英]Jupyter notebook cannot find module
I'm trying to load a module called folium
into my Jupyter Notebook environment.我正在尝试将名为
folium
的模块加载到我的 Jupyter Notebook 环境中。 When I attempt to load this module, a ModuleNotFoundError
is returned.当我尝试加载此模块时,会返回
ModuleNotFoundError
。
When I run !pip list
in the same Jupyter Notebook environment, folium
is listed amongst my installed modules.当我在同一个 Jupyter Notebook 环境中运行
!pip list
时, folium
列在我安装的模块中。
How do I successfully load this module?如何成功加载此模块?
Could it be that you expect a certain Python installation (virtual environment) to be used in Jupyter, but Jupyter is using a different kernel?难道你期望在Jupyter中使用某个Python安装(虚拟环境),但Jupyter使用的是不同的kernel?
With that assumption, I believe all you need to do is to add the virtual environment to Jupyter as a kernel. In more detail:有了这个假设,我相信您需要做的就是将虚拟环境作为 kernel 添加到 Jupyter。更详细地说:
virtualenv
, which nowadays seems to be the recommended way of working ( see Python docs ), but there are other options as well:virtualenv
,现在似乎是推荐的工作方式(参见 Python 文档),但还有其他选项:
pip install --user virtualenv
if it is not installed yet (it is installed by default for the newer Python versions). pip install --user virtualenv
如果尚未安装(默认情况下安装较新的 Python 版本)。 By the way, personally, I use Poetry instead of pip
for a while now, and I like it a lot.pip
,我非常喜欢它。cd <path>
) and create the environment with python3 -m venv <my_venv_name>
. cd <path>
)并使用python3 -m venv <my_venv_name>
创建环境。source <my_venv_name>/bin/activate
(deactivate with deactivate
).source <my_venv_name>/bin/activate
环境(使用deactivate
)。ipykernel
is installed ( pip install --user ipykernel
)ipykernel
( pip install --user ipykernel
)python3 -m ipykernel install --user --name=<any_name_referring_to_your_venv>
.python3 -m ipykernel install --user --name=<any_name_referring_to_your_venv>
将 venv 添加到 Jupyter。 Now you should be able to select in Jupyter this environment as a kernel, and all packages installed in that venv should be picked up by Jupyter automatically as well (you'll need to restart the kernel in that case though).现在你应该能够在 Jupyter 这个环境中将 select 作为 kernel,并且安装在那个 venv 中的所有包也应该由 Jupyter 自动获取(尽管在这种情况下你需要重新启动 kernel)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.