Home > Back-end >  How can I get VSCode integrated terminal in MacOS to launch correct version of Python?
How can I get VSCode integrated terminal in MacOS to launch correct version of Python?

Time:12-30

I recently installed Python 3.10.1 on MacOS and I'm trying to set up VSCode as my file editor and integrated terminal. I successfully installed the Python extension, as you can see in lower left corner of screenshot. However, when I open a terminal session and check the version of Python, it displays 2.7.18.

[![screenshot of VSCode window][1]][1]

I tried various settings in the settings.JSON file, including "terminal.integrated.inheritEnv:false" [as recommended in various SO posts][2], but it didn't help. Can someone help me set the integrated terminal to launch Python 3.10.1?

Here are a few facts that might be helpful:

  • I'm running MacOS Monterey 12.0.1
  • The path to Python 2.7 is /usr/bin, and these files are dated October 17, 2021. However, I checked my Mac's system history and nothing was installed or updated on that date. No apps, and not MacOS. But I know that Python is a key part of basic MacOS functioning, so I don't want to delete or update this, at risk of messing up other stuff.
  • The path to Python 3.10 is /usr/local/bin, and these files are dated December 11, 2021, which is the date that I downloaded Python from python.org as a DMG file and run the install utility.
  • If I launch Idle (the editor that same with my new Python installation) and check the version, it says 3.10
  • If I launch the generic terminal app -- in bash or zsh -- and check the version, it says 2.7.8

Last thing: if I type the "echo $PATH" command from the integrated terminal, I get the following:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/Apple/usr/bin
/usr/local/mongodb/bin```


  [1]: https://i.stack.imgur.com/AniyE.png
  [2]: https://stackoverflow.com/questions/54582361/vscode-terminal-shows-incorrect-python-version-and-path-launching-terminal-from

CodePudding user response:

Open User Settings.json and add

"python.defaultInterpreterPath": "<path to python3>"

Reload window, create a new folder and open it in VS Code, the extension should use python3 as interpreter.

CodePudding user response:

I was able to solve my problem by changing that "python3" alias name to just "python" and adding another line to the settings.JSON that says: "python.pythonPath": "/usr/local/bin/python"

  • Related