I'm using an iMac with High Sierra. I used Anaconda to install both python 2.7.15 and python 3.6.5. I created virtual environments for both of these. I'm trying to learn python and I'm using Visual Studio Code. I've run scripts fine that were developed for python 3 but the code I'm currently working with was developed for python 2. I can not get VScode to run using a python 2 interpreter, it seems to use python 3 no matter what I do. I could rewrite the script to make it compatible with python 3 but I'd rather not do that. I've tried running VScode from the python 2 virtual environment but that seems to have no effect. I edited the settings in VScode and changed the variable python.pythonPath to point to python 2 but that doesn't work. I used the command pallet to change the python interpreter but that doesn't work either. How do I force VScode to run python 2.
1 Answer
Start VScode and open your python script. Using either the command palette or the status bar, select the python interpreter you wish to use. Both options present a list of available interpreters. Now you may run your code by right-clicking in the edit window and selecting "Run python file in terminal". A terminal window opens below the edit window and your code executes there. Note: You must execute your code using the right-click technique described above. Other methods, such as using the command palette with "run: code", will not work