I am a student of Python and I will try to present a step by step guide about ‘How To Use Python With Visual Studio Code?’. I will be listing down the steps I found and followed to setup Visual Studio Code to debug and run python code. If you think I missed something please do let me know in the comments section.
Step 1: Install Python
It sounds very obvious to many but, for those who are new to Python as well as Visual Studio Code I would like to inform you that Visual Studio Code can be used to debug and run Python code. But, ‘Visual Studio Code doesn’t come with Python‘. So, we will have to install python separately. Please use this official Python download link to get the latest Python. (There is big debate whether to use Python 2.x or 3.x? I don’t want to get into it for now. Just use the latest version of Python. That’s what sane people say!). Python installation is very simple i.e. Double click!
Tips :
- I prefer to use custom path for Python installation e.g. “C:\Python\” because the default path C:\Users\<user name>\AppData etc. etc. is not easy to find on the machine.
- If you are new to Python do not touch other default options.
- Python 3.6+ has a new option at the end that can disable MAX_PATH limit. Disable that limitation. It’s good.
Step 2 : Install Visual Studio Code
Now another (obviously) important step is to install Visual Studio Code. Visual Studio Code is a Microsft’s free Code editor. You can visit it’s official website for further details. But, in short it is Visual Studio without any compiler. It’s only a code editor. Users have to install plugins in order to perform certain tasks which are particular to the programming language. Visit it’s official download page, download the latest version and install. You can choose 64x or 32x as per your choice.
Tip: You can choose to select auto installation for supporting tools for Python from Welcome page. (Please see at top right of the Welcome page) Or you can install the extensions Individually as I will mention in Step 3 below.
Step 3: Install Extensions For Python
Click on the Square button on left button panel. It is is the ‘Extensions Button’. Natural question is ‘Why do we need extensions?’ Answer is simple, ‘Because Visual Studio Code is just a Code Editor and is not built to compile any code as such. So, to help coupling the compiler and Visual Studio Code, we need Extensions’
Please install the following Extensions as shown in the picture below. (Use search box at the top for finding these Extensions). These extensions are more than sufficient to debug and run a Python code
- Python
- Python for VSCode
- MagicPython
- Python Extended