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:
- Install & activate your virtual environment. Below I'll use
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.
- Go to the desired directory (with
cd <path>) and create the environment with python3 -m venv <my_venv_name>.
- Activate the environment with
source <my_venv_name>/bin/activate (deactivate with deactivate).
- Make sure
ipykernel is installed (pip install --user ipykernel)
- Add the venv to Jupyter with
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).
%pip install foliumin a cell inside your notebook. Then restart the kernel. If that doesn't help, try the same with%conda install -c conda-forge folium. If you haven't encountered use of%with pip & conda before inside notebooks, see here. Essentially, don't use ! anymore in the notebook with pip & conda. You are better off with nothing ibeforepiporcondain notebook as automagics will handle.!does is send out that task to your system's shell I believe, and so what it may be listing withpip listthere isn't necessarily what is in the environment backing the notebook kernel. I think. Or the installation is botched and that is why it can show installed with!pip listand not work. (Would be interesting before you run my suggested solution steps above if you ran!pip listand then%pip listin your notebook and see if they show different things in regards to folium.) Anyway, using the magics is always better now.%pip listI cannot seefoliumlisted, so clearlyfoliumisn't installed in the environment backing the notebook kernel. I've installed it using%pip install folium, and can now load it successfully. Can you suggest a resource where I can learn about how and where packages are installed (i.e. so that I can learn from first principles why I had this issue). Thanks for all your help.