How to set Python3 as default interpreter for VS Code | or set any version as default interpreter.

Want to run your python code with a particular python version in Microsoft VS Code? And, make it the default version?
Read on.
Make sure that the required version is installed. You check the available version and the path by running this command.

I am trying this on Apple Mac. It should be similar in Windows Machines as well.

 

Open the VS Code, at the bottom of the screen you will Terminal. If it is not visible, Go to View and then select Terminal.



Check the available python versions and their path. 


 % which python  

/usr/bin/python



 % which python2

/usr/bin/python2



 % which python3 

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3


Next, 


Run this python code to check what version is used by default. 


import platform
print(platform.python_version_tuple())
print(type(platform.python_version_tuple()))



You will get this


('2', '7', '16')

<type 'tuple'>



Now you know the path and versions available.

In the VS code, go to the View menu and select Command Pallete



Now search for Python and you will get all the installed versions of Python.



Then select Python: Select interpreter. You will get all the installed versions of python. Select the one you want to be associated with your script.


Now run the same code again to check what is the default version set.


import platform
print(platform.python_version_tuple())
print(type(platform.python_version_tuple()))


('3', '7', '1') <class 'tuple'>


No comments:

Post a Comment

FREE 50 Linux Interview Questions and Answers for Beginner Level

Desclainer: Please note that the answers to these questions are correct to my knowledge. Please feel free to comment if you find any incorre...