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
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:
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.
When you open a python file, the python version of the current workspace will be displayed in the lower right corner.
Of course, this is your choice. You can also click it and select other python interpreters.
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:
Using the
pip
command directly on the above terminal to install the package will be directly installed in thevenv
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 ispip install ...
.In addition, you can manage the conda environment and its packages within the Anaconda Navigator.
About the pyhton environment in vscode.