Last Updated on April 26, 2021
Below is a step-by-step instruction on how to run Python3 Virtualenv in PowerShell.
The tutorial below assumes that you have already installed python3 and pip3 in your windows computer.
virtualenv in Python3
In PowerShell, install
virtualenv using python pip.
pip3 install virtualenv
Create a virtual environment
Error when activating newly created virtual environment
To activate the the Virtual Environment that you have created, you will need to run the command
activate.ps1 script inside the Scripts folder. If this is your first time activating virtualenv it will lead to the
File activate.ps1 cannot be loaded because running scripts is disabled on this system.
By default PowerShell does not allow running of ps1 scripts. To fix this we will need to allow our user to run PowerShell scripts.
Open PowerShell as Administrator and run the command below. This will enable running of ps1 in PowerShell.
It will then warn you that changing the execution policy might expose you to some security risks. Type
y and press
Now that we have enabled running scripts in PowerShell, activate your virtual environment by running the command below.
This will put a
(virtualenv_name) before your prompt, this indicates that your virtual environment has been activated.
To deactivate your virtual environment run the command below.
Disable running PowerShellScripts
I usually do not do this since I regularly need running virtualenv, but if you want you can revert back to disabling running PowerShell scripts.
To do this, run the command below using PowerShell running as Administrator.
We hope that the above helped you run virtualenv in PowerShell.