I run into this error "running scripts is disabled on this system" as I was trying to activate the virtual environment on PowerShell.

Picture of the author

This error happens because the venv\Scripts\activate command tries to run the Activate.ps1 PowerShell script to activate the virtual environment on your system.

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.

Picture of the author

The following steps show you how to fix the error.

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] Note: You don't need to close the PowerShell window where you got the error. {: .notice--warning} <$>

Picture of the author

Allow Windows PowerShell to Execute Scripts

To fix the error, you need to change the PowerShell execution policy to remotesigned. This will allow you to run scripts that are on your local computer unsigned, and also remote scripts(from the internet) which have been signed.

Type the following command in the PowerShell admin window to change the execution policy:

  1. set-executionpolicy remotesigned

You will be prompted to accept the change, type A(Yes to all), and press ENTER on your keyboard to allow the change.

Picture of the author

Close the PowerShell admin window, and go back to the PowerShell Window where you got the error. Run the command that triggered the error again. Mine was venv\Scripts\activate.

If you look at the following screenshot, you will see that am not getting the error anymore and the virtual environment has been activated:

Picture of the author

I hope your error has been fixed too. Let me know in the comments if you have any questions. Thank you for reading.