Reputation: 23
I'm trying to load a module called folium
into my Jupyter Notebook environment. When I attempt to load this module, a ModuleNotFoundError
is returned.
When I run !pip list
in the same Jupyter Notebook environment,
folium
is listed amongst my installed modules.
How do I successfully load this module?
Upvotes: 2
Views: 5478
Reputation: 88
Could it be that you expect a certain Python installation (virtual environment) to be used in Jupyter, but Jupyter is using a different 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:
virtualenv
, which nowadays seems to be the recommended way of working (see Python docs), but there are other options as well:
pip install --user virtualenv
if it is not installed yet (it is installed by default for the newer Python versions). By the way, personally, I use Poetry instead of pip
for a while now, and I like it a lot.cd <path>
) and create the environment with python3 -m venv <my_venv_name>
.source <my_venv_name>/bin/activate
(deactivate with deactivate
).ipykernel
is installed (pip install --user ipykernel
)python3 -m ipykernel install --user --name=<any_name_referring_to_your_venv>
.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).
Upvotes: 2