How to create a virtual environment in Windows 11 for Python projects

Creating a Virtual Environment in Windows 11 for Python Projects Setting up a virtual environment is a crucial step for managing dependencies in Python projects. It allows developers to isolate project-specific requirements, ensuring that dependencies

Written by: Leo Nguyen

Published on: January 7, 2026

Creating a Virtual Environment in Windows 11 for Python Projects

Setting up a virtual environment is a crucial step for managing dependencies in Python projects. It allows developers to isolate project-specific requirements, ensuring that dependencies do not clash between projects. This guide will walk you through the steps necessary to create a virtual environment in Windows 11, complete with best practices, detailed instructions, and troubleshooting tips.

Step 1: Install Python

Before creating a virtual environment, ensure that Python is installed on your Windows 11 system.

  1. Download the Installer:

    • Visit the official Python website to download the latest version of Python for Windows.
  2. Run the Installer:

    • Open the downloaded installer.
    • Make sure to check the box that says “Add Python to PATH”.
    • Click “Install Now” and follow the prompts to complete the installation.
  3. Verify the Installation:

    • Open Command Prompt by pressing Win + R, typing cmd, and hitting Enter.
    • Type python --version and pip --version. You should see the installed versions.

Step 2: Update pip

Before creating a virtual environment, ensure that pip (the Python package installer) is up to date.

  1. Open Command Prompt.
  2. Type the following command and press Enter:
    python -m pip install --upgrade pip

Step 3: Install the virtualenv Package (Optional)

Though Python 3.3+ includes the venv module for creating virtual environments, many developers prefer the virtualenv package for its additional features. Here’s how to install it:

  1. In Command Prompt, execute:
    pip install virtualenv

Step 4: Create a New Directory for Your Project

Organizing your projects in separate directories helps maintain clarity and structure.

  1. Choose a location for your new project. For example, C:UsersYourUsernameProjects.
  2. Create a new directory:
    mkdir MyPythonProject
    cd MyPythonProject

Step 5: Create a Virtual Environment

You can create a virtual environment using either venv or virtualenv.

Using venv:

  1. If you prefer to use Python’s built-in venv, run:
    python -m venv venv

    This will create a directory named venv within your project folder.

Using virtualenv:

  1. If you opted for virtualenv, run:
    virtualenv venv

This command also generates a folder named venv, containing the isolated Python environment.

Step 6: Activate the Virtual Environment

Once the virtual environment is created, you must activate it to start using it.

  1. Navigate to the Scripts directory of the virtual environment:

    cd venvScripts
  2. Activate the environment by typing the following command:

    activate

    After activation, your Command Prompt will show the environment name, indicating that it is active.

Step 7: Install Dependencies

With the environment activated, you can start installing packages specific to your project.

  1. Use pip to install the required packages:
    pip install package_name

    For example:

    pip install requests

Step 8: Verify Installed Packages

To check the packages installed in your virtual environment, you can use:

pip list

This command lists all installed packages along with their versions.

Step 9: Deactivate the Virtual Environment

Once you are done working in the virtual environment, you can deactivate it by simply typing:

deactivate

This exits the virtual environment and returns you to the global Python environment.

Step 10: Reactivate the Virtual Environment

Whenever you want to continue working on your project, you can reactivate the virtual environment:

  1. Open Command Prompt.
  2. Navigate to your project directory:
    cd C:UsersYourUsernameProjectsMyPythonProject
  3. Activate it again:
    venvScriptsactivate

Best Practices for Using Virtual Environments

  • Create a new virtual environment for each project: This eliminates potential conflicts in dependencies.
  • Use a requirements file: Save dependencies to a requirements.txt file using:
    pip freeze > requirements.txt

    You can later install these dependencies in another environment by running:

    pip install -r requirements.txt
  • Regularly update virtual environments: To maintain security and compatibility, keep your packages updated using:
    pip install --upgrade package_name

Troubleshooting Common Issues

  • Command not found: Ensure Python and pip are correctly installed and added to your PATH.
  • Permission errors: Run your Command Prompt as an administrator to circumvent issues related to user permissions.
  • Activation issues: If you encounter problems when activating, verify that you’re navigating to the Scripts directory of the correct virtual environment.

Conclusion

By following these straightforward steps, you can effectively create and manage a virtual environment in Windows 11 for your Python projects. This practice not only enhances your workflow but also ensures that your projects are organized and maintainable. Whether you’re developing a simple script or a complex application, virtual environments are invaluable for isolating dependencies, thus leading to a smooth development experience.

Leave a Comment

Previous

The economics of being a Python developer: San Francisco versus remote work

Next

Understanding Python’s Import System and Circular Dependencies