Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ By default, this is ``%USERPROFILE%\Envs``.
~~~~~~~~~~~~~~~~~~~~
**pywin** python version switcher (not included)

PowerShell Support
==================

PowerShell support has been added to this project. Windows PowerShell users can now use `virtualenvwrapper`-like functionality with familiar commands.

Installation
------------

1. Place the ``virtualenvwrapper.ps1`` file in a suitable directory.
2. Open your PowerShell profile:

.. code-block:: powershell

notepad $PROFILE

3. Add the following line at the end of the profile file:

.. code-block:: powershell

. "C:\path\to\virtualenvwrapper.ps1"

Usage
-----

.. code-block:: powershell

mkvirtualenv myenv # Creates and activates a new virtual environment
workon myenv # Activates an existing virtual environment
workon # Lists all available environments
rmvirtualenv myenv # Removes the specified virtual environment

Note
----

This script provides a user experience similar to the original ``virtualenvwrapper`` on Linux/macOS systems.


If you use several versions of python, you can switch between them
using a separate project `pywin
<https://github.com/davidmarble/pywin>`_. It's a lightweight
Expand Down
53 changes: 53 additions & 0 deletions scripts/virtualenvwrapper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$env:WORKON_HOME = "$HOME\Envs"

function workon {
param (
[String]$env
)
if ($env) {
if (Test-Path "$env:WORKON_HOME\$env\Scripts\activate.ps1") {
. "$env:WORKON_HOME\$env\Scripts\activate.ps1"
}
else {
Write-Host "virtualenv '$env' does not exist."
Write-Host "Create it with 'mkvirtualenv $env'"
}
}
else {
Write-Host "Pass a name to activate one of the following virtualenvs:"
Write-Host "==============================================================="
Get-ChildItem $env:WORKON_HOME -Name
}
}

function mkvirtualenv {
param (
[String]$env
)
if ($env) {
python -m venv "$env:WORKON_HOME\$env"
. "$env:WORKON_HOME\$env\Scripts\activate.ps1"
}
else {
Write-Host "Please provide a name for the virtual environment."
}
}

function rmvirtualenv {
param (
[String]$env
)
if ($env) {
if (Test-Path "$env:WORKON_HOME\$env") {
Removeස
Remove-Item -Path "$env:WORKON_HOME\$env" -Recurse -Force
Write-Host "Deleted $env:WORKON_HOME\$env"
}
else {
Write-Host "virtualenv '$env' does not exist."
}
}
else {
Write-Host "Please provide a name for the virtual environment."
}
}
Loading