I run into this error “running scripts is disabled on this system” as I was trying to activate Python’s virtualenv on Powershell.
This error happens because the
venv\Scripts\activate command tries to run the
Activate.ps1 Powershell script to activate the virtual environment.
Note: .ps1 is an extension for powershell scripts.
It turns out on my Windows 10 system, the Execution Policy is set to restricted by default. This means that Powershell cannot execute any script.
Here is how I fixed the error:
Step 1: Open Windows Powershell as Admin
Open the Start menu on Windows and search for powershell and right-click on it. Click on “run as administrator”.
Note: You don’t need to close the Powershell window where you got the error.
Step 2: Type the following command the new Powershell window:
> set-executionpolicy remotesigned
This command will allow you to run scripts that are on your local computer(unsigned) and remote scripts(from the internet) which have been signed.
Step 3: You will be prompted to run accept the change, type Y(Yes) and press enter on your keyboard to allow the change.
Step 4: Close the Powershell admin window, and then go back to the Powershell Window(where you got the error) and run the command again.
The command has worked! virtualenv has been activated.
(venv) PS C:\Users\Stanley\django_project>