'How to change interpreter in Visual Studio Code?
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?
Solution 1:[1]
All you have to do is press ctrl+shift+p Then will get a search bar kinda thing on top of the screen.
Then type the following command:
> python: select interpreter
You will be provided with options. Select the one you want to use.
Solution 2:[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.
Solution 3:[3]
Download and install the python version that you want https://www.python.org/downloads/
Open the visual studio code
Click on the Bottom left for the version
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | ClayD |
Solution 3 | |
Solution 4 | oriku |