virtualenv in PowerShell?

There seems to be a problem when virtualenv is used in PowerShell.

When I try to activate my environment in PowerShell like...

env/scripts/activate

.. nothing happens. (the shell prompt should have changed as well as the PATH env. variable .)

I guess the problem is that PowerShell spawns a new cmd. process just for running the activate.bat thus rendering the changes activate.bat does to the shell dead after it completes.

Do you have any workarounds for the issue? (I'm sticking with cmd.exe for now)


The latest version of virtualenv supports PowerShell out-of-the-box.

Just make sure you run:

Scripts\activate.ps1

instead of

Scripts\activate

The latter will execute activate.bat, which doesn't work on PowerShell.


My original answer is now outdated. Now, just use activate.ps1 (rather than activate.bat) to activate from a Powershell environment.


Original answer:

Here's a post that contains a Powershell script that allows you to run batch files that persistently modify their environment variables. The script propagates any environment variable changes back to the calling PowerShell environment.


A quick work-around would be to invoke cmd and then run your activate.bat from within the cmd session. For example:

PS C:\my_cool_env\Scripts> cmd
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\my_cool_env\Scripts>activate.bat
(my_cool_env) C:\my_cool_env\Scripts>

Inside of the Scripts directory of your virtual environments folder there are several activation scripts that can be used depending on where you are executing the command. If you are trying to activate your virtual env from the Windows PowerShell, try using the following command:

. .\env\Scripts\activate.ps1

In the event you receive an error about the activation script being disabled on your system, you will first need to invoke an execution policy change on your system. This will need to be done as the administrator.

To do this:

1) Right click on the PowerShell application and select Run as Administrator

2) Run the following command: Set-ExecutionPolicy Unrestricted

3) Rerun the activation command: . .\env\Scripts\activate.ps1


Run the this command:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force

followed by:

./env/Scripts/activate.ps1

That's all