Newest version of virtualenv (16.7.2) on python v.3.7.4 has 4 additional lines for the "activate.ps1" script, which when run on Windows10 powerhsell gives the error: You must 'source' this script: PS> . .\ENV\Scripts\activate
How do I fix this? (please note that I have read and done all that was mentioned on the other forum questions as well as the manual for virtualenv related to windows and powershell.)
I have set the execution policy to RemoteSigned (as recommended in other forums):
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
When I want to activate virtualenv, I run .\ENV\Scripts\activate
The problem is with lines 3 to 6 of the activate.ps1 script that is auto generated by virtualenv when you make a new virtual environment:
if (@($null,"Internal") -notcontains $myinvocation.commandorigin) {
Write-Host -Foreground red "You must 'source' this script: PS> . $($myinvocation.invocationname)"
exit 33
}
It seems that $myinvocation.commandorigin
is set to Runspace instead of Internal
How do I fix this? Any ideas? Thanks :)))
Note that I don't want to manually adjust every auto-gen activate.ps1
file.
Let's have a look at that error message:
You must 'source' this script: PS> . .\ENV\Scripts\activate
Hmmmm... - PS>
is probably just the prompt, which leaves us with this:
. .\ENV\Scripts\activate
# ^
# |
# Check out this guy
That, the lonely .
in front of the path, that is the dot-source operator in powershell.
According to the documentation, it:
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope.
I haven't had a look at virtualenv
, but I assume it'll want to define a number of variables and to ensure that these persist after the script has run, it needs to be run in the current scope.
So this is the literal command you have to run to fix it:
. .\ENV\Scripts\activate
Screenshot attached for reference. I've just encountered the same issue but I did the following:
Create a new virtual environment;
python -m venv directory
Navigate into the newly created directory;
cd directory
Activate the virtual environment.
.\Scripts\activate
This resolved my problem. I hope it helps...
I have also faced this issue. To solve this I created a new virtualenvironment as follows:
python -m venv directory-name
To activate:
Scripts>./activate
And Now it's working fine...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With