virtualenv v16.7.2 powershell activate script: "You must 'source' this script: PS> . .\ENV\Scripts\activate" error

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

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...


Screenshot attached for reference. I've just encountered the same issue but I did the following:

  1. Create a new virtual environment;

    python -m venv directory

  2. Navigate into the newly created directory;

    cd directory

  3. Activate the virtual environment.

    .\Scripts\activate

This resolved my problem. I hope it helps...