Python "venv" is not activated, What should you do?

Python "venv" is not activated, What should you do?

Sam: I face one issue while activating the venv environment in Python, so what should I do for this?

Lingaraj: Ok, Sam I can help you with that. Sam said, How? Let's see this issue arises on your system.

"File D:\python-06-07-2023\venv\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/"

So you follow these steps:

The error you're encountering is related to the PowerShell execution policy on your system, which is restricting the execution of scripts, including the activation script for the virtual environment. The default execution policy on Windows is often set to "Restricted," which prevents the execution of any scripts.

To resolve this issue, you can change the execution policy to allow the activation script to run. Here's how you can do it:

  1. Open PowerShell as an Administrator: Right-click on the PowerShell icon and select "Run as Administrator" to open PowerShell with elevated privileges.

  2. Check the Current Execution Policy: Run the following command to check the current execution policy:


    It will likely return "Restricted."

  3. Change the Execution Policy: To change the execution policy, use the following command:

     Set-ExecutionPolicy RemoteSigned

    You may be prompted to confirm the change. Type "Y" and press Enter.

    Alternatively, if you only want to change the policy for the current session, you can use:

     Set-ExecutionPolicy RemoteSigned -Scope Process
  4. Activate the Virtual Environment: Now, go back to your VS Code terminal and try activating the virtual environment again:


    This should work without the previous error.

  5. Revert the Execution Policy (Optional): After you've activated your virtual environment, you may want to revert the execution policy to its previous state for security reasons. To do this, run:

     Set-ExecutionPolicy -Default

    This sets the execution policy back to the system default.


Remember that changing the execution policy carries some security implications, so it's important to understand the risks associated with allowing script execution. Ensure that you're comfortable with the security implications before making these changes.

Did you find this article valuable?

Support LingarajTechhub All About Programming by becoming a sponsor. Any amount is appreciated!