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

48 views Asked by At

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?

2

There are 2 answers

0
JialeDu On BEST ANSWER
  • For .py scripts

    Ctrl+Shift+P --> Python: Select Interpreter

    enter image description here

  • For Jupyter Notebook

    Click Select Kernel in the upper right corner (Or the kernel version already shown) Select Python Environments....

    enter image description here

    enter image description here

These are two different ways of choosing a python environment.

0
Afreeth K. H. On

try anaconda software, in this software contain jupiter notebook but its doesn't contain any error to interpret python program and its interpreter is good working condition than VScode.