11

I have installed on my system several Python interpreters, 2.x and 3.x versions. I am trying to prepare my work environment to allow easily switch between code written in both Python version. It is really important to have as much flexible setting in Visual Studio Code (VSC). The problem is that I have no idea how to set VSC terminal to run code in Python 2.x. Terminal output is needed because it allows to provide user input easily. I've tried instructions provided on VSC page, like manual interpreter's path indication in folder or workspace setting. I reinstalled Python 2.x to ensure PATH variable has been updated. When I run code with CodeRunner extension, it always run it in Python 3.x. Does anyone have similar issue and found how to change Python environment used by this integrated terminal?

2
  • Seems that it is needed to manually change the PATH variable. Re-installation of interpreter may not change it, even if user is sets this in installation setup. After manual PATH edition, terminals uses correct interpreter. Commented Dec 1, 2017 at 22:17
  • Also, when using workspaces and folders ensure that appropriate "python.exe" is indicated in respective settings. Commented Dec 2, 2017 at 9:00

4 Answers 4

15

All you have to do is press ctrl+shift+p or ++p Then will get a search bar kinda thing on top of the screen.

Then type the following command:

> python: select interpreter 

enter image description here

You will be provided with options. Select the one you want to use.

Sign up to request clarification or add additional context in comments.

Comments

2

At the bottom of the MS Code screen is an info bar that lets you know what line, col, text encoding, etc... It also shows the python interpreter you are accessing.

If you click on the text for the version of python that is running, it will open a list of available interpreters on your system. If 2.7 is in your path, you can select it.

1 Comment

It won't change the interpreter used by the integrated terminal though.
2
  1. Download and install the python version that you want https://www.python.org/downloads/

  2. Open the visual studio code

  3. Click on the Bottom left for the version

enter image description here

  1. Select the version that you want the code to be complied enter image description here

3 Comments

I had this option but it was recently removed. Do you know how I can readd it?
It won't change the interpreter used by the integrated terminal
It looks like they removed this functionality. Now you have to do it via the Command Palette: Ctrl+Shift+P > Search for Interpreter > python:select interpreter
0

Answers above won't change interpreter in the visual-studio's terminal as explained. You can see for yourself. (I'm on linux)

which python3 # /usr/bin/python3 

You can't export a new PATH because it'll ruin your other commands. And neither you can directly change the 'python3' file via root privileges. It doesn't work that way.

Your best option is to reshape your system interpreter according to your needs.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.