Set Up Python, pip, and VS Code Virtual Environments in Windows 10/11

Set Up Python, pip, and VS Code Virtual Environments in Windows 10/11​

Difficulty: Beginner | Time Required: 20 minutes
Python is one of the easiest programming languages to start with on Windows, but many beginners run into the same problem: packages get installed in the wrong place, VS Code uses a different Python version than expected, or a project works one day and breaks the next. The fix is to set up Python, pip, and a project-specific virtual environment correctly from the beginning.
A virtual environment keeps each Python project isolated. That means one project can use one set of packages while another project uses something completely different. In this tutorial, you’ll install Python, confirm pip is working, install Visual Studio Code, create a virtual environment, and connect it to VS Code on Windows 10 or Windows 11.

Prerequisites​

Before you begin, you need:
  1. A Windows 10 or Windows 11 PC.
  2. An internet connection.
  3. A standard user account with permission to install apps.
  4. Windows Terminal, PowerShell, or Command Prompt.
Tip: Windows Terminal is included on many Windows 11 systems and is available for Windows 10 from the Microsoft Store. PowerShell works fine for all commands in this guide.

Step 1: Install Python​

You have two beginner-friendly options: install Python with winget, or install it manually from the official Python installer.

Option A: Install Python using winget​

  1. Right-click Start.
  2. Select Terminal or Windows PowerShell.
  3. Run:
winget install Python.Python.3
  1. Wait for the installation to finish.
  2. Close and reopen PowerShell.
Note: If Windows says winget is not recognized, use the manual installation method below.

Option B: Install Python manually​

  1. Download the latest Windows installer from the official Python website.
  2. Run the installer.
  3. On the first installer screen, check:
Add python.exe to PATH
  1. Select Install Now.
  2. When setup completes, close the installer.
  3. Open a new PowerShell window.
Warning: Do not skip the Add python.exe to PATH option unless you already know how to manage PATH manually. Beginners should enable it.

Step 2: Verify Python is installed​

In PowerShell, run:
py --version
You should see something like:
Python 3.x.x
Now also try:
python --version
On most properly configured systems, this should also show your Python version.
Tip: On Windows, the py command uses the Python Launcher, which is helpful when multiple Python versions are installed. For beginner use, py is often the safest command.

Step 3: Verify pip is installed​

pip is Python’s package installer. It is used to install libraries such as requests, flask, django, numpy, and many others.
Run:
py -m pip --version
If pip is installed, you will see its version and the Python folder it belongs to.
Next, upgrade pip:
py -m pip install --upgrade pip
Note: Using py -m pip is usually better than typing only pip, because it makes sure pip runs with the Python version selected by the Windows Python Launcher.
If pip is missing, try:
py -m ensurepip --upgrade
Then check again:
py -m pip --version

Step 4: Install Visual Studio Code​

If you already have VS Code installed, you can skip this step.

Install with winget​

Open PowerShell and run:
winget install Microsoft.VisualStudioCode

Or install manually​

  1. Download Visual Studio Code from the official VS Code website.
  2. Run the installer.
  3. During setup, enable the options to add VS Code to PATH and add “Open with Code” actions if you want them.
  4. Finish the installation.
After installation, open VS Code from the Start menu.

Step 5: Install the Python extension in VS Code​

  1. Open Visual Studio Code.
  2. Select the Extensions icon on the left sidebar.
  3. Search for:
Python
  1. Install the official Python extension from Microsoft.
  2. If prompted, also allow related Python tools or environment extensions to install.
The Python extension adds interpreter selection, IntelliSense, debugging, environment support, and package management features.

Step 6: Create a project folder​

Now create a clean folder for your first Python project.
  1. Open File Explorer.
  2. Create a folder such as:
Documents\PythonProjects\hello-python
  1. Open VS Code.
  2. Select File > Open Folder.
  3. Choose your hello-python folder.
Tip: Always open the project folder itself in VS Code. This makes environment detection and settings much easier.

Step 7: Create a virtual environment​

In VS Code:
  1. Select Terminal > New Terminal.
  2. Make sure the terminal opens in your project folder.
  3. Run:
py -m venv .venv
This creates a hidden-style project folder named .venv. It contains a private Python interpreter and package location for this project.
Note: .venv is a common name for virtual environments in Python projects. It is easy for VS Code to detect and easy for other developers to understand.

Step 8: Activate the virtual environment​

In PowerShell, run:
.\.venv\Scripts\Activate.ps1
After activation, your prompt should show something like:
(.venv) PS C:\Users\YourName\Documents\PythonProjects\hello-python>
That (.venv) prefix means the virtual environment is active.
If PowerShell blocks the activation script, you may see an execution policy message. For a beginner-friendly fix, run:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Then try activating again:
.\.venv\Scripts\Activate.ps1
Warning: Only run scripts from sources and projects you trust. Changing the execution policy for the current user is common for development, but you should still be careful with downloaded scripts.
If you prefer Command Prompt instead of PowerShell, activate with:
.venv\Scripts\activate.bat

Step 9: Select the virtual environment in VS Code​

VS Code often detects .venv automatically. If it does not:
  1. Press Ctrl+Shift+P.
  2. Search for:
Python: Select Interpreter
  1. Choose the interpreter inside your project’s .venv folder.
It will usually look similar to:
.\.venv\Scripts\python.exe
Once selected, VS Code uses that environment for running, debugging, IntelliSense, and package discovery.

Step 10: Test your setup​

Create a new file in VS Code named:
hello.py
Add this code:
print("Hello from Python on Windows!")
Run it by selecting the Run Python File button, or use the terminal:
python hello.py
You should see:
Hello from Python on Windows!

Step 11: Install a package with pip​

With the virtual environment still active, install a test package:
python -m pip install requests
Now create a file named:
test_requests.py
Add:
Code:
import requests

print("Requests is installed correctly.")
print(requests.__version__)
Run it:
python test_requests.py
If you see the installed version number, your virtual environment and pip setup are working.
Tip: Once inside an activated virtual environment, python -m pip install package-name installs packages into that environment, not globally into Windows.

Step 12: Save dependencies with requirements.txt​

To record the packages used by your project, run:
python -m pip freeze > requirements.txt
This creates a file listing installed packages and versions.
Later, you or another user can recreate the same package setup with:
python -m pip install -r requirements.txt
Best Practice: Do not copy the .venv folder between computers. Share your code and requirements.txt, then recreate the environment on each PC.

Tips and troubleshooting​

VS Code is using the wrong Python version​

Press Ctrl+Shift+P, run Python: Select Interpreter, and choose the interpreter from .venv.

pip installs packages globally instead of in .venv​

Make sure your prompt starts with:
(.venv)
If not, activate the environment again.

The python command opens the Microsoft Store​

Use:
py --version
If Python is installed properly, py should find it. You can also check Windows app execution aliases in Settings > Apps > Advanced app settings > App execution aliases.

I created the venv in the wrong folder​

Delete the unwanted .venv folder, open the correct project folder in VS Code, and run:
py -m venv .venv

How do I exit the virtual environment?​

Run:
deactivate
You can reactivate it any time from the project folder.

Conclusion​

You now have a clean Python development setup on Windows 10 or Windows 11. Python is installed, pip is working, VS Code knows which interpreter to use, and your project has its own isolated virtual environment. This setup helps prevent package conflicts, keeps projects organized, and makes it much easier to share or rebuild your work later.
Key Takeaways:
  • Install Python and verify it with py --version.
  • Use py -m pip or python -m pip for reliable package installation.
  • Create one .venv virtual environment per project.
  • Select the .venv interpreter in VS Code.
  • Use requirements.txt to save and recreate project dependencies.

This tutorial was generated to help WindowsForum.com users get the most out of their Windows experience.

Structured References​

  • Microsoft Learn: Windows Python development environment setup, including Python, VS Code, and the Python extension. (code.visualstudio.com)
  • Visual Studio Code documentation: Python tutorial, interpreter selection, environments, package management, running, and debugging behavior. (code.visualstudio.com)
  • Python documentation: venv virtual environments and Windows activation commands. (docs.python.org)
  • Python and pip documentation: ensurepip, python -m pip, package installation, and requirements-file usage. (docs.python.org)

References​

  1. Citation: code.visualstudio.com
  2. Citation: docs.python.org
  3. Related coverage: pip.pypa.io
  4. Related coverage: packagemanager.org
  5. Related coverage: pip-python3.readthedocs.io
  6. Related coverage: packaging.python.org
  1. Related coverage: pip-test.readthedocs.io
  2. Related coverage: docs.pyth.onl
  3. Related coverage: pip.dokyumento.jp
  4. Related coverage: pradyunsg-pip.readthedocs.io
  5. Related coverage: app.readthedocs.org
  6. Related coverage: assets-global.website-files.com
 

Back
Top