Installing and Setting up Python in Visual Studio Code

Jenny ManJenny Man
11 min read

📚 In this article, I will walk you through the steps I took to install and set up Python and Visual Studio Code on my Windows machine. I’ll cover everything from installation to creating and managing files.


Install Python on Windows

Step 1: Download the Python Installer

Visit the official Python website and download the latest version of Python for Windows. The site will automatically detect your operating system and recommend the appropriate installer.

Step 2: Run the Python Installer

Open your “Downloads” folder and double-click the Python installer to run it. A Python Setup window will pop up.

Step 3: Select Configurations for Python Install

Check the “Add python.exe to PATH” option if:

PATH environment variable
List of folders that your computer searches through to figure out where to look for executable files when you run a command in the command prompt or terminal.
  • You want to use python or pip commands easily from any terminal window.

  • You prefer not to rely on the py launcher for Windows.

  • python command starts the Python interpreter, and it runs Python scripts.

  • pip command is used for managing Python packages.

  • py launcher is included by default when you install Python on Windows. The py command starts the system’s default Python version, runs Python scripts, and manages multiple versions of Python. It’s super convenient, but if you’re wondering about managing multiple Python versions more efficiently, virtual environments are a great option — and I’ll dive into what I learned about them in another post. For now, here is a little brief on what is a virtual environment.

A virtual environment is like a sandbox for your project, where you can install the specific dependencies you need — with the right version numberwithout interfering with the system-wide installation. This isolation reduces the risk of version conflicts between different projects, helping keep everything running smoothly.

Select “Install Now” if you want to install Python with the default settings.

  • Python will be installed into your user directory.

  • The standard library, test suite, py launcher for Windows, and pip will be installed.

  • Shortcuts will only be visible for the current user.

Select “Customize installation” if you want to change the installation directory, select specific features, or perform an all-users installation.

When you select “Customize installation”, you’ll see “Optional Features”, allowing you to select specific features to install. The py launcher for Windows will be installed into the Windows directory. When you’re done with the selection, click Next.

In “Advanced Options”, there are several options to choose from. By default, the “Customize install location” is set to your user directory. Choose an install location that is easy to access, well-organized, and won’t conflict with other system programs or tools.

For individual use, choose your user directory.

Suggested location: C:\Users\<Username>\Python\<version> Be sure to replace Username with your actual username and version with the Python version.

For all users, check the “Install Python <version> for all users” option and choose the Program Files directory.

Suggested location: C:\Program Files\Python\<version> Be sure to replace version with the Python version.

Step 4: Install Python

After selecting your desired installation settings, click Install and wait for the installation to finish. Then click Close.

Step 5: Verify the Installation

After the installation is finished, you can confirm that Python was installed correctly by opening the Windows Command Prompt and running the following command based on your VS Code installation setup:

How to Open Windows Command Prompt
Press Windows + R > type “cmd” > press Enter.

If you checked the “Add python.exe to PATH” option during install: Type python --version or python -V then press Enter, and you should see the installed Python version.

If you did not check the “Add python.exe to PATH” option during install: Type py --version or py -V then press Enter, and you should see the installed Python version.


Set up Python on Visual Studio Code

💡
Prerequisite: Python is installed on your machine.

Step 1: Download the Visual Studio Code Installer

Visit the official Visual Studio Code website and download the latest version of VS Code for Windows. The site will automatically detect your operating system and recommend the appropriate installer.

Step 2: Run the VS Code Installer

Open your “Downloads” folder and double-click the VS Code installer to run it.

A VS Code Setup window will pop up. Click the “I accept the agreement” option then click Next.

Step 3: Select Configurations for VS Code Install

Select Destination Location: Choose where you want to install VS Code. To continue, click Next. If you would like to select a different location for installation, click Browse.

Select Start Menu Folder: Choose where you want to place the program shortcuts. To continue, click Next. If you would like to select a different folder, click Browse.

Select Additional Tasks: Select which additional tasks you would like “Setup” to perform while installing VS Code, then click Next.

  • Create a desktop icon: Creates a shortcut icon for VS Code on your desktop.

  • Add “Open with Code” action to Windows Explorer file context menu: Adds an “Open with Code” action in the right-click context menu for files in Windows Explorer, making it easy to open files in VS Code.

  • Add “Open with Code” action to Windows Explorer directory context menu: Adds an “Open with Code” action in the right-click context menu for directories (folders) in Windows Explorer, making it easy to open folders in VS Code.

  • Register Code as an editor for supported file types: Makes VS Code the default code editor for certain file types.

  • Add to PATH (requires shell restart): Adds VS Code to the PATH environment variable, which allows you to launch VS Code from any command prompt or terminal by running the code command.

Step 4: Install VS Code

Ready to Install: Click Install and wait for the installation to finish. Then click Finish.

Step 5: Install Extensions in VS Code

On the left navigation bar, click the “Extensions” icon to browse through the extensions marketplace.

Python — adds Python language support. Type “Python” in the search bar then click Install for Python from Microsoft.

indent-rainbow (Optional) — makes indentation in coding easier to read. Type “indent-rainbow” in the search bar then click Install.

Rainbow Brackets 2 (Optional) — provides multi-color highlight of matching brackets. Type “rainbow brackets 2” in the search bar then click Install.


Managing Files and Folders in VS Code

Step 1: Creating and Opening Files in VS Code

Method 1: Using VS Code

  • Open VS Code, if not already opened. Navigate to File menu then click New File… or click New File… in the Welcome tab.

  • A pop-up should show up in the middle of the VS Code window prompting you to choose what type of file to create. Click the Python File option.

  • A new Untitled-1 tab will open next to the Welcome tab. Press Ctrl + S to rename the file and select a save location.

  • The untitled file name will be updated to reflect the name you entered. To ensure your file is saved as a python file rather than a text file, check the file’s name extension and icon. Files with the .py extension will display a Python icon.

Method 2: Using Windows File Explorer

Create a new python file via Windows File Explorer

  • Press Windows + E or click on the folder icon on your taskbar to open Windows File Explorer.

  • Navigate to the location where you want to create your new python file.

  • Ensure file extensions are visible. If not, click the View tab at the top left of the “File Explorer” window then check the “File name extensions” box.

  • Right-click an empty space to open the context menu, hover over “New”, then select “Text Document”.

  • By default, the file name will be “New Text Document.txt”. Update it with a new name and change the file extension from .txt to .py. Click Yes to the warning that pops up.

Open the new Python file via Windows File Explorer.

  • Double-click the newly created Python file, select “Visual Studio Code”, then click OK to open it in VS Code.

Method 3: Using Command Prompt

Create a new python file via Command Prompt

  • Press Windows + R top open the “Run” dialog.

  • Type “cmd” then press Enter to open the “Command Prompt”.

  • Type cd C:\path\to\that\directory (e.g. cd C:\Users\<UserName>\Documents) to navigate to the directory where your new file will be created. Be sure to replace UserName with your actual username, then press Enter.

    cd
    Stands for “change directory”. cd [<path\to\your\directory>] is used in command prompt to navigate between directories (folders) on your computer.
  • Type type nul > <FileName>.py (e.g. type nul > test2.py) to create an empty python file. Be sure to replace FileName with the file name you want, then press Enter.

    type nul > <FileName>.py
    type is used in command prompt to display the contents of a file. nul in Windows is a null device representing “nothing”. When combined together, type nul means “display the contents of nothing”, which outputs nothing. > is an operator that takes that output and redirects it into a file, creating an empty file.
  • Check that your file was created by running the dir command to display the list of contents in the current directory. Your new file should be displayed in the output.

    dir
    Stands for “directory”. It’s used in command prompt to list all the files and folders in the current directory. dir [<path\to\your\directory>] (e.g. dir C:\Users\<UserName>\Documents) lists the contents of a specified directory.

Open the new Python file in VS Code via Command prompt.

  • Type code <FileName>.py (e.g. code test2.py) then press Enter to open the specified file in VS Code. Your new file will be displayed in the Code editor panel. Note: code command works if you checked the “Add to PATH” option during VS Code installation.

    code
    code is used in command prompt to open VS Code with no file/folder, just a blank window. code <FileName>.py opens a specific Python file in VS code. code . opens the current folder in VS Code.

Step 2: Creating and Opening Folders in VS Code

Method 1: Using Windows File Explorer

Create a new folder via Windows File Explorer.

  • Press Windows + E or click on the folder icon on your taskbar to open Windows File Explorer.

  • Navigate to the location where you want to create your new folder.

  • Press Ctrl + Shift + N and you can immediately rename the newly created folder or right-click an empty space to open the context menu, hover over “New”, then select “Folder”.

Open the new folder via Windows File Explorer.

  • Right-click on the newly created folder to open up the context menu. Then select “Open with Code”*. VS Code will open up and display your folder in the *Explorer panel.

Method 2: Using Command Prompt

Create a new folder via Command Prompt.

  • Press Windows + R top open the “Run” dialog.

  • Type “cmd” then press Enter to open the “Command Prompt”.

  • Type cd C:\path\to\that\directory (e.g. cd C:\Users\UserName\Documents) to navigate to the directory where your new folder will be created. Be sure to replace UserName with your actual username, then press Enter.

  • Type mkdir "<FolderName>" (e.g. mkdir “python files”) to create your folder. Be sure to replace FolderName with the name you want to give the folder, then press Enter.

    mkdir
    Stands for “make directory”. mkdir "<FolderName>" is used in command prompt to create a new folder in the current directory. mkdir [<path\to\your\directory>] (e.g. mkdir C:\Users\<UserName>\Documents) creates a new directory in the specified directory. mkdir [<folder1> <folder2>] (e.g. mkdir folderA folderB) creates multiple folders at once — each space separates a new folder name.
  • Check that your folder was created by running the tree command to display the directory name. Your new folder should be displayed in the output as a tree-like diagram.

    tree
    It’s used in command prompt to display a graphical tree-like structure of all the directory names along with the paths and files in each subdirectory.

Open the new folder in VS Code via Command prompt.

  • Type cd <FolderName> (e.g. cd python files) to navigate to that newly created folder, then press Enter. Your directory path will be updated to show that you are now inside that folder.

  • Run the code . command to open the current directory in VS Code. Your folder will be displayed in the Explorer panel. Note: code command works if you checked the “Add to PATH” option during VS Code installation.

Step 3: Creating Files and Subfolders within an Already Opened Folder in VS Code

Create File: Hover over the folder name in the Explorer panel and you will see several icons show up. Click the “New File…” icon, and you can immediately rename the newly created file. By default, VS Code creates a .txt file type. To make it a Python file type, simply add the .py extension to your file name. Then press Enter to confirm the name.

Create Subfolder: Hover over the folder name in the Explorer panel and you will see several icons show up. Click the “New Folder…” icon, and you can immediately rename the newly created subfolder. Then press Enter to confirm the name.


🎉 Thanks for Joining Me on This Journey!

Thank you for reading along and being part of this learning adventure. I hope this guide helps you get started with Python and VS Code too. If you’re also on a coding journey, feel free to share your thoughts and experiences in the comments! My next post will be about virtual environments so if you’re interested, please follow and subscribe to my newsletter 😊.

0
Subscribe to my newsletter

Read articles from Jenny Man directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jenny Man
Jenny Man

I'm starting my journey as a programmer with a focus on Python and test automation. Experience in quality assurance, test case design, and defect management. Passionate about driving product quality and continuous learning in the tech field.