Create a Python Project in Visual Studio Code

This procedure walks you through creating a new Python project in Visual Studio Code, complete with a virtual environment so the project’s packages stay isolated from the rest of the system.

🧰 Prerequisites

Install all three before continuing. The steps below assume they are already set up.

📋 Steps

  1. Open Visual Studio Code.

  2. Open the Explorer Tab and click Open Folder.

  3. Create a new folder or choose an existing one.

  4. Open the Command Palette with Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac).

  5. Type Python: Create Environment and select it from the list.

  6. Select Venv. This creates a virtual environment, a private space where the project keeps its own copy of Python and its packages, separate from every other projects.

  7. Select the Python interpreter to use. This is the version of Python that will run the code. If only one is installed, pick that one.

  8. Confirm the name .venv for the virtual environment.

  9. Select Skip Package installation.

  10. Wait for VS Code to finish creating the environment.

  11. When finished, a .venv folder will appear in the project, and the new environment is selected automatically.

  12. In the Explorer Tab, click the New File icon next to the folder name.

  13. Name the file main.py and press Enter.

  14. Open main.py and add a single line: print("Hello, World!").

  15. Save the file

    • Windows/Linux: Ctrl+S
    • Mac: Cmd+S

🎯 Expected Outcome

  1. The project folder contains a .venv folder.
  2. The project folder contains a main.py file.
  3. main.py contains a single line: print("Hello, World!").

⚠️ Mistakes

No folder open before creating the environment

The virtual environment and files are created inside whichever folder is open in VS Code. Without a folder open, there is nowhere for them to live, and VS Code cannot create the environment. Always open a folder first via File → Open Folder before starting.

Python not installed

The Python extension helps you write Python, but it does not include Python itself. Without Python installed, the Create Environment step has no interpreter to choose and cannot finish.

Skipping the virtual environment

It is possible to create main.py without an environment, and a single line will still run. But installing packages later without a virtual environment mixes them into the system-wide Python, where they can clash with other projects. Creating the environment first, as a habit, avoids that from the start.

📚 Resources