pythonvisual-studio-codejupyter-notebookjupyterinterpreter

When using a jupyter notebook in VSCode, the Python interpreter is ignored


I have a virtual environment with some installed packages and a notebook with some imports of packages that only exist in this environment.

I have done Ctrl + Shift + P > Python: Select Interpreter, and chosen my environment.

But, if I run the cell, it tells me ModuleNotFoundError, as it tries to use my global Python environment for the imports (if I install the packages globally the cell succeeds).

Therefore, the selected Interpreter is ignored, and the global environment is always used.

I also tried using my environment in: Jupyter: Select Interpreter to Start Jupyter Server, but the result did not change.

This problem does not exist in a python file, only in the jupyter notebooks.

How to fix it? Am I forced to install packages globally when using Jupyter Notebooks?


Solution

  • These are two different ways of choosing a python environment.