How to create Virtual Environments Python Windows

Python venv is a built-in module in Python 3 that provides a mechanism for creating and managing virtual environments. A virtual environment is an isolated Python environment that allows you to install packages and dependencies specific to a particular project without interfering with the global Python installation or other projects.

Create Virtual environment python demo

To create a virtual environment for Python on Windows, you can use the built-in venv module. Follow these steps:

Step #1 Open the Command Prompt or PowerShell on your Windows machine.

Step #2 Navigate to the directory where you want to create the virtual environment. You can use the cd command to change directories. For example:

cd C:\codetryout

Step #3 Create a new virtual environment using the python -m venv command followed by the desired name for the environment. For example:

python -m venv devops

This will create a new virtual environment named “devops” in the current directory.

Step #4 Activate the virtual environment

Activate the virtual environment by running the activate script specific to the virtual environment. In Command Prompt, run:

devops\Scripts\activate

In PowerShell, run:

devops\Scripts\Activate.ps1

After activation, you should see the virtual environment name in your command or PowerShell prompt.

Step #5 Now, you are inside the virtual environment. You can install Python packages and run Python scripts without affecting the global Python installation.

Step #6 To deactivate the virtual environment, run the deactivate command in the Command Prompt or PowerShell.

With this, you have successfully created a virtual environment for Python on Windows using venv. You can repeat these steps to create multiple virtual environments for different projects or purposes.

Related to creating a virtual environment Python