This is a mimic of the powerfull virtualenvwrapper but for Windows Powershell.
Unless the previous version of my esteemed colleague Guillermo Lòpez equivalent but obsolete it's compatible with Python 2+ and entierly based on a PowerShell script.
Just use the Install.ps1
script:
./Install.ps1
and the script will create required path if needed and install the profile.ps1
file directly to
automaticly activate VirtualEnvWrapper when the shell is opened
Put the file VirtualEnvWrapper.psm1
into the directory ~\Documents\WindowsPowerShell\Modules
.
Edit or create the file ~\Documents\WindowsPowerShell\Profile.ps1
(see )
and add into the lines below :
$MyDocuments = [Environment]::GetFolderPath("mydocuments")
Import-Module $MyDocuments\WindowsPowerShell\Modules\VirtualEnvWrapper.psm1
The virtual environments directory is set into your personnal directory : ~/Envs
Where ~
is your personnal directory.
If you want to set your environment. Just add and variable environment called :
WORKON_HOME
(as in Unix/Linux system).
The module add few commands in Powershell :
lsvirtualenv
(alias: Get-VirtualEnvs) : List all Virtual environmentsmkvirtualenv
(alias: New-VirtualEnv) : Ceate a new virtual environmentrmvirtualenv
(alias: Remove-VirtualEnv) : Remove an existing virtual environmentworkon
: Activate an existing virtual environmentGet-VirtualEnvsVersion
: to display the current version.
To create a virtual environment just type:
MkVirtualEnv -Name MyEnv -Python ThePythonDistDir
where MyEnv
is your environment and ThePythonDistDir
is where the python.exe
live. For example:
MkVirtualEnv -Name MyProject -Python c:\Python36
will create and virtual environment named MyProject
located at ~\Envs
with the Python 3.6 distribution located at C:\Python36
If the -Python
option is not set, the python command set in your path is used by default.
Options are:
-Name
: The new environment name-Packages
or-i
: Install packages separated by a coma (Note: this differs from original virtualenvwrapper )-Associate
or-a
: Still todo-Requirement
or-r
: The requirement file to load.
If both options Packages and Requirement are set, the script will install first the packages then the requirements as in original Bash script.
Type
LsVirtualEnv
in a Powershelll to display the entiere list with the Python version.
For Example:
Python Virtual Environments available
Name Python version
==== ==============
TheProjectIHave 3.6.3
Type
workon TheEnvironment
in a console. The PS command line starts now with:
(TheEnvironment) C:\Somewhere>
to show you what is the default
To ensure that the Python environment is the good one type:
Get-Command python
The path should be:
~\Envs\TheEnvironment\Scripts\python.exe
Just type deactivate
as usual (Python default).
- Activate the autocompletion
- Set the virtualenvwrapper options into system environment variables (see the main project)
A script InstallDev.ps1
exists to simplify the development. Invoke it with:
$ .\InstallDev.ps1
will unload VirtualEnvWrapper.ps1
from memory and reload it.