2

python 3.7.1 Windows 10 Powershell

Steps taken:
create folder for envs
change to folder
pip install virtualenv virtualenv "abc"
abc\Scripts\activate

This throws the error stated in the title. I have tried activate and activate.ps1. They both result in the error. activate.bat doesn't get the error but it doesn't work either.

I have tried running PS as administrator and searched google and stackoverflow. Myself and one other user on stackoverflow seem to be the only two people with this problem.

Details:

Output from activate.ps1:

PS D:\GoogDrive\flask> noc\Scripts\activate.ps1  
You must 'source' this script: PS> . noc\Scripts\activate.ps1  
PS D:\GoogDrive\flask>  

Output from activate.bat:

PS D:\GoogDrive\flask> noc\Scripts\activate.bat  
PS D:\GoogDrive\flask>  

Also, when I do pip list, it always shows me all the modules in my base install.

tripleee
  • 3,121
  • 5
  • 32
  • 35
bsbaixo
  • 23
  • 1
  • 5
  • `activate` is a shell script for Unix. The correct command for Powershell is `abc/Scripts/activate.ps1`. You seem to have misspelled `Scripts` but then the error message would be different. Can you please [edit] your question to show *exactly* what output you get from `abc/Scripts/activate.ps1`? – tripleee Aug 04 '19 at 09:16
  • Running as administrator is entirely the wrong thing to do here. The whole point of `virtualenv` is to separate your environment from system-wide settings and defaults which require privileged access to manipulate. – tripleee Aug 04 '19 at 09:18
  • tripleee, re: admin rights, yes, that is a good point. I only tried it that way to eliminate rights as being the culprit. Thanks for your feed back! Also, "GoogDrive" is correct, its not misspelled on this PC. – bsbaixo Aug 04 '19 at 12:32

1 Answers1

3

Like the error message specifically says, the correct way to run the script is to source it:

. noc\Scripts\activate.ps1

The single dot is an alias for the source command. This causes the script to be run in the current session, rather for the shell to start a new subshell, run the script, and exit (thus losing any environment changes that the script attempted to make).

tripleee
  • 3,121
  • 5
  • 32
  • 35
  • I'm not a PowerShell person but in this case the error message is basically identical to a common error I see with Bash users. – tripleee Aug 04 '19 at 12:44
  • Nailed it! Thanks so much. This is my first question, I checked the green check mark, anything else I need to do? – bsbaixo Aug 04 '19 at 13:51
  • That's all good, thank you very much. Clicking the up arrow is strictly optional, though of course I'd appreciate it. See also [help.](/help/someone-answers) – tripleee Aug 04 '19 at 14:09