-4

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
  • 2
    Please provide at least the code containing the imports. At which module import does it throw the error? This problem can have many roots. First, for notebooks, you should select kernels with the Notebook: Select Notebook Kernel command in VSCode. Try and see if that works. Commented Mar 23, 2024 at 15:59
  • The error happens on the imports. The answer was to select the Notebook Kernel on the top right corner, which I did not see. Commented Apr 2, 2024 at 20:01

2 Answers 2

1
  • 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.

Sign up to request clarification or add additional context in comments.

Comments

-2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.