2

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.

Derlin
  • 8,518
  • 2
  • 22
  • 42
  • And does `workon` by itself give you a list of possible virtualenvs? –  Sep 03 '15 at 01:18
  • Yes it does. I can see the virtualenvs that were created when i use workon but i can't activate them using workon . – Stefan Cardenas Sep 03 '15 at 01:27
  • Can you activate the virtualenv in the standard manner: `source /bin/activate`? (The exact form may depend a bit on the shell you're using.) –  Sep 03 '15 at 01:49
  • PS C:\Users\Stefan\envs\rango\scripts> source C:\Users\Stefan\envs\rango\scripts/activate source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + source C:\Users\Stefan\envs\rango\scripts/activate + ~~~~~~ + CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – Stefan Cardenas Sep 03 '15 at 01:56
  • I received the above response from the terminal when i typed in your suggestion. – Stefan Cardenas Sep 03 '15 at 01:56
  • Sorry, my bad (and lack of Windows knowledge); apparently, the command is something like [`C:\Users\Stefan\evns\rango\scripts\activate`](https://virtualenv.pypa.io/en/latest/userguide.html#activate-script). No need to use `source`, just run the `activate` script. –  Sep 03 '15 at 02:02
  • 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 – Stefan Cardenas Sep 03 '15 at 02:43
  • I'm afraid that's where my knowledge stops, but it does give you more information on what is wrong: apparently there are permission issues. –  Sep 03 '15 at 11:14
  • Hint: [edit] your question and add that last result to the question; that makes it much clearer for other readers than having to read through comments (which don't allow much mark-up either). –  Sep 03 '15 at 11:15

1 Answers1

0

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