virtualenv in PowerShell?


Question

Hi fellow pythonistas, 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)

1
28
9/2/2009 2:36:52 AM

Accepted Answer

Update: The answer below is out of date. Now, just use activate.ps1 (rather than activate.bat) to activate from a Powershell environment.

Here's a post which contains a Powershell script which 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.

13
11/24/2018 3:33:18 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon