skip to Main Content

I am trying to set up python on my mac (as a first time user). The problem i encounter is that my interpreter is Python 3.11.4. But in my terminal the python version is only Python 3.9.13. How can i change this?

Because of this issue i am unable to install any library. I get this is the VS code terminal:

(base) dana@Danas-Air Python % pip install numpy
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (1.25.1)

But when i try to load the library, i get an error:

ModuleNotFoundError: No module named 'numpy'

This might have an obvious solution, but i havent been able to find it anywhere. I also looked into the setting and made sure that the box saying “Activate Python Environment in Terminal created using the Extension” is unchecked.

enter image description here

enter image description here

2

Answers


  1. Seems like you are using anaconda as a virtual environment. VSCode uses the OS’s Python by default. In order for VSCode to use the correct Python interpreter, the command palette must be called up via F1 and the correct interpreter can be referred to with "Python Select interpreter".

    Another way to set the interpreter is clicking the python Version on the bottom left side in VSCode
    enter image description here

    By pressing the Python Version (here 3.8.10 64-bit) you can choose another Interpreter path

    Disable conda at default Startup

    VSCode Terminal often use the default conda environment. To disable this, run following command in VSCode Terminal

    conda config --set auto_activate_base False
    

    Control your Python Interpreter and pip installation location

    check your python interpreter and pip path

    which python3
    which pip
    

    Try to install new packages with the pip from your default python interpreter you use with:

    python3 -m pip install PACKAGE
    
    Login or Signup to reply.
  2. There should be several different versions of python environments on your machine.

    But when i try to load the library, i get an error:

    ModuleNotFoundError: No module named 'numpy'
    

    The picture shows that your numpy is installed in the python 310 environment, but you are currently using the python 311 interpreter. Apparently there is no numpy in python 311. You can install numpy on python 311 or switch to python 310 (Ctrl+Shift+P –> Python: Select Interpreter).

    enter image description here

    Then explain why the version displayed by the terminal is different from that displayed by vscode, because vscode uses the computer terminal as an integrated terminal, so when you type python in the terminal, it will use the one configured in the environment variable path. And the python version displayed in the lower right corner of vscode is the interpreter you choose for the Python extension.

    If you choose a virtual environment for vscode, the new terminal (Ctrl+Shift+`) will automatically activate the environment

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search