Tuesday, February 1, 2022

[SOLVED] Virtualenvwrapper-win installed on Windows 10 but can't activate virtual environment

Issue

When I try to activate the virtual environment using the command workon <name>, the virtual environment does not activate. I am using a Windows 10 machine and installed Virtualenv, VirtualenvWrapper, and VirtualenvWrapper-win .

For example when I input lsvirtualenv into the command shell I can see that the <name> virtual environment exists but I can not activate it. Can you please help me?

edit #1:

When I try to activate the file directly I receive the following error from the terminal:

PS C:\users\stefan\envs\rango\scripts> .\activate .\activate : File C:\users\stefan\envs\rango\scripts\activate.ps1 cannot be loaded. The contents of file C:\users\stefan\envs\rango\scripts\activate.ps1 might have been changed by an unauthorized user or process, because the hash of the file does not match the hash stored in the digital signature. The script cannot run on the specified system. For more information, run Get-Help about_Signing.. At line:1 char:1 + .\activate + ~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : Unauth – 

EDIT 2 -

I was able to get it to work by running powershell as administrator and changing the execution policy to "remotesigned". See below for method:

If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell with the "Run as administrator" option:

PS> Start-Process powershell -Verb runAs

The current execution policy may be identified using the Get-ExecutionPolicy cmdlet:

PS C:\Users\Administrator> get-executionpolicy

In order to change the prevailing execution policy, the Set-ExecutionPolicy cmdlet is used in conjunction with the new execution policy setting. For example, to change to RemoteSigned, the following command should be executed:

PS C:\Users\Administrator> set-executionpolicy remotesigned

Execution Policy Description Restricted The default policy on Windows PowerShell, this mode disables the execution of script files. Windows PowerShell may only be used by manually issuing commands at the command prompt.

AllSigned Limits execution to scripts which are authenticode signed. When a signed script is executed, PowerShell will prompt for confirmation that the signer of the script can be trusted.

RemoteSigned Requires that any scripts that have been downloaded from a remote location must be signed before they may are permitted to execute.

Unrestricted Allows any script to be executed, regardless of origin or whether it is signed.


Solution

From the virtualenv docs, one possible solution would be to relax the system execution policy to allow running of local scripts without verifying the code signature.

To do that, run powershell as an administrator, cd to your C:> directory and type the following command:

PS C:\> Set-ExecutionPolicy RemoteSigned


Answered By - Florent Chatterji
Answer Checked By - David Marino (WPSolving Volunteer)