Skip to main content

How to Successfully Set Up Visual Studio Code with Python - Complete Walkthrough

Requirements

Install Visual Studio Code available here: Install VS Code. Download and install Python on your PC: Install Python.

Create your python project

Open Visual Studio code and then click on open folder to create a new folder for your project:

VS Code welcome screen with Open folder link highlighted in the Start section

Create a new folder:

Windows File Explorer with New folder button highlighted in the toolbar

Select the folder:

Folder browser dialog with Code folder selected and Select Folder button highlighted

The new project opens up on VS Code:

VS Code with new project folder open in Explorer sidebar showing SAMPLE CODE directory and Welcome tab

Make sure you have the python extension for VS Code installed:

VS Code Extensions Marketplace showing Microsoft Python extension installed with 21.6M downloads and 4.5 star rating

Set up your environment variables

1. To set up workspace settings for Python.

Go to File > Preferences > Settings. Select Workspace Settings and in the Search bar enter the key word pythonpath:

VS Code Workspace Settings with pythonpath search, Python Path setting highlighted with empty input field

Copy the path to the python.exe file installed on your PC:

Windows File Explorer showing Python36-32 install directory with python.exe selected and address bar path highlighted

Paste the path in the Python Path setting, highlighted below:

VS Code Workspace Settings with Python Path field populated with the full path to python.exe highlighted

2. To set up environment variables for pip3.

Right click on This PC > Properties > Advanced system settings > Environment Variables.

Edit the environment variable ‘path’:

Windows Environment Variables dialog with System variables Path selected and Edit button highlighted

Browse to the directory where the pip3 exe file is available. pip3 is usually found inside the Scripts folder (under the same directory of python.exe).

Select OK to add the path to the environment variable:

Edit environment variable dialog showing Path entries list with Browse button highlighted to add pip3 Scripts directory

Now we have set up the required environment variables.

Create a new file

Click on the file icon to create a new file. Give the file a name ending with the extension ".py" (stands for python):

VS Code Explorer sidebar with New File icon highlighted next to the SAMPLE CODE project folder

You are now ready to code your new program:

VS Code with communicate_over_REST.py file open in the editor, Python setup complete and ready for coding