Jupyter ignores the virtual environment interpreter I set
Using PyCharm Professional 2023.2.3 on Windows.
I have a base Python interpreter, and I've created a virtual environment in my project from this base interpreter, adding some extra packages. This virtual environment interpreter is selected for the project. It is well recognized when running a pure .py file or opening a Python console.
PROBLEM : However, this venv interpreter is not used when running a Jupyter notebook, despite the fact that I properly set it in the “Python interpreter” field of the “Jupyter servers” configuration for that notebook. It looks like the Jupyter notebook ignores this setting of the python interpreter, and use the base interpreter instead.
For instance, in the notebook, importing one of the extra package leads to a “ModuleNotFoundError”, despite the fact it is well recognized by the IDE (no red squiggles below), and despite the fact that on a .py file or python console, the module is well loaded.
Please sign in to leave a comment.
For the record, I found this is linked to the kernel, even if I don't quite completely get the logic.
The kernel that is used by default uses specs from the base interpreter, even when the venv interpreter is set in Pycharm.
A way to circumvent this is to :
* Open a terminal with the venv activated
* Create a new kernel using : python -m ipykernel install --user --name=venv_kernel
* Then on the kernel dropdown menu of the notebook, select that “venv_kernel” (or whatever you named it).
But I still wonder if there is a way to do this automatically, so I don't have to do this manually each time I'm creating a venv and want to use it with Jupyter ?
(note : I'm not using conda/anaconda)
I had the same issue. Configured venv but the default kernel was not using it. Davids post help me to resolve it.