skip to Main Content

There are two Python versions on my Mac. One in Anaconda, the other in VS Code. When I try to install libraries for the Python in VS Code by terminal, it always goes to Anaconda. What shall I do in this case?

I tried to install directly from VS Code, but that always resulted in a syntax error. Then, I Googled the issue and was told to install the libraries by terminal. But when I tried to install from terminal, the libraries were always installed in the Anaconda, not in VS Code.

2

Answers


  1. Assuming that the Python environment that comes with VS Code is located in the /usr/bin directory, you can use the following command to install a package using the correct version of pip:

    /usr/bin/python3 -m pip install

    This command specifies the full path to the pip executable that’s associated with the Python environment that comes with VS Code, and then uses the -m flag to run pip as a module of that Python environment.

    By using this command, you can make sure that the package is installed in the correct Python environment, and not in the Anaconda environment.

    Login or Signup to reply.
  2. When you open a python file, the python version of the current workspace will be displayed in the lower right corner.

    enter image description here

    Of course, this is your choice. You can also click it and select other python interpreters.

    enter image description here

    Generally, when you select an interpreter and create a new terminal, the terminal will automatically activate the environment, which is controlled by the following settings:

    "python.terminal.activateEnvironment": false
    

    enter image description here

    Using the pip command directly on the above terminal to install the package will be directly installed in the venv virtual environment.

    In addition, it should be noted that the command for the conda installation package is conda inatall ..., and the command for the general python installation package is pip install ....

    In addition, you can manage the conda environment and its packages within the Anaconda Navigator.

    enter image description here

    About the pyhton environment in vscode.

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