Reputation: 513
I cannot for the life of me get VS Code to run Python 3. I've installed Python 3 and followed several VS Code tutorials to get it set up. I've set the user settings to point to my install of Python 3: "python.pythonPath": "/usr/local/bin/python3"
However, every time I run python in the terminal within VSC, it is Python 2.7. When I try to install anything using pip, I get warnings that 2.7 will no longer be supported etc.
As an example, when I try to install something with pip, I get the following error:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/urllib3-1.25.3.dist-info' Consider using the
--user
option or check the permissions.
Any ideas? It's driving me crazy that I simply can't get VSC to switch to Python 3.
Upvotes: 3
Views: 2530
Reputation: 394
python2.7 was the first widely stable version of python and came pre-installed on unix like OS such as Mac and Linux after it's acceptance. Many python apps have been built on python2.7 although python2.7 has been discontinued. However, it is still maintained with bug fixes. Most applications and OS that support python usually default to python2.7 that usually gets invoked using python. to use python version 3, append 3 to python (python3). python3 libraries and plugins are mostly differentiated from default python with an appendage of 3 to the library name or plugin name such pip3. As a result you have both versions of python live on your system without conflicts. Note that you cannot port python 2.7 codes to python3
Upvotes: 0
Reputation: 1057
Mac has python version 2 set as default and usually does not come with pip preinstalled or is linked with version 2. I recommend leaving it that way. Use version 3 for your personal use cases and leave your Mac with version 2 as default. As you have to install python3 yourself, means you might also want to check/install pip3.
Check if you have python 3 installed:
python3 --version
Check if you have pip3 installed (usually included by default since python 3.4):
pip3 --version
Set VS Code to use Python3 on the bottom right corner, which you should see when having a .py file open:
And now if you want to import any modules into python, make sure to install them with pip3:
pip3 install package_name
If you run into permission issue again, you might consider to run the command with sudo rights:
sudo pip3 install package_name
Upvotes: 1
Reputation: 11
I had the same error (ArchLinux), and VS Code also worked with Python 2 by default
You need to go into VS Code -> File -> Preferences -> Settings -> Extensions -> Python. Then find the configuration of the Python Path, and instead of Python, specify Python3, or, as in my case, Python3.8.
configuration of the Python Path After that, I switched from the Python 2 version to Python 3, but the error remained. So I took advantage of this article and turned off pylint
https://code.visualstudio.com/docs/python/linting
Upvotes: 0
Reputation: 3780
Try using pip3 install instead of pip install, pip is most likely linked against pip2.
Upvotes: 0