VirtualEnvs (venv) and Powershell

Cameron Simpson cs at zip.com.au
Sat Apr 1 18:32:57 EDT 2017


On 31Mar2017 19:03, Carl Caulkett <carl.caulkett at gmail.com> wrote:
>I've just started to investigate VirtualEnvironments as a means of
>preventing my 3rd party code becoming chaotic. I've discovered that
>venv's can be managed quite effectively using Powershell. When
>Activate.ps1 is run, the PowerShell changes to indicate that the venv
>is active which is nice. However despite the official documention,
>there doesn't seem to be a corresponding Deactivate.ps1. There is a
>deactivate.bat but that doesn't appear to switch the paths back to
>their pre-env state.
>   What I would really like is a Git-Bash based alternative to
>Powershell to manage my Virtual Environments. Has anyone dicovered
>tools or techniques to achieve this?

Well, in a UNIX environment the natural things is simply to start a shell using 
the target venv. Thus:

  sh -c '. /path/to/the/venv/bin/activate; exec $SHELL'

or even simpler:

  ( . /path/to/the/venv/bin/activate; exec $SHELL )

That would get you a prompt using the virtualenv by default. To reset to the 
old settings, exit that subshell.

Maybe I misunderstand your needs.

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list