1
votes

I have had trouble for months using packages and libraries in VS Code. Everytime I create and activate a new python virtual environment in VS Code, it defaults back to using the MacOS pre-installed python 2.7.10. A picture below shows my issue. I would like to see "/usr/local/bin/python3" when I type the command "python --version", instead I get "/usr/bin/python". Does anyone know how to fix this? Thanks.

Picture of problem

2
This doesn't look like a VSCode problem but rather a terminal/shell problem. You'll probably want to inspect your PATH variable for anything funky. - BallpointBen
@chef stu -How are things going? Just checking in to see if the information provided was helpful. - Jill Cheng
@JillCheng Not good so far. I've created a virtual environment to see if this fixes the issue. When I echo "$PATH", the path correctly includes .../env/bin of which includes a Python 3; however, it still fails to include any libraries downloaded into the bin as well as still using version 2.7.10 after running python --version. - chef stu
@chef stu -Have you tried resetting the location of python environment variables and reopening VS Code? - Jill Cheng

2 Answers

0
votes

I'm not a MacOS user and can't see your picture due to my network, but you can create the virtual environment with a specific version of Python.

On Windows this is:

python3.8 -m venv envname

If you are creating a virtual environment by using python -m venv envname the issue is the default interpreter on your PC is set to Python 2. A quick search shows you might be able to set a different global version on a Mac with something like pyenv global 3.8.6. I'm not sure if this would have other implications for you.

0
votes
  1. Please try to open a new VS Code terminal to let it reload the currently selected python environment. (Terminal; New Terminal; shortcut keys: Ctrl+Shift+`)

    enter image description here

  2. For the global python environment in VS Code, even though we have switched the python environment, sometimes its internal terminal still uses the first python of the python environment variable. Therefore, it is recommended that you move the python you need to use to the first: (Please reopen VS Code after setting.)

    enter image description here