Skip to content

A mimic of the VirtualEnvWrapper project but with Powershell

License

Notifications You must be signed in to change notification settings

lyonels/virtualenvwrapper-powershell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VirtualEnvWrapper for Windows Powershell

This is a mimic of the powerfull virtualenvwrapper but for Windows Powershell.

Unless the previous version of my estimated colleague Guillermo Lòpez equivalent but obsolete it's compatible with Python 2+ and entierly based on a PowerShell script.

Installation

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

###Manual Installation 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

Location

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).

Usage

The module add few commands in Powershell :

  • lsvirtualenv (alias: Get-VirtualEnvs) : List all Virtual environments
  • mkvirtualenv (alias: New-VirtualEnv) : Ceate a new virtual environment
  • rmvirtualenv (alias: Remove-VirtualEnv) : Remove an existing virtual environment
  • workon: Activate an existing virtual environment
  • Get-VirtualEnvsVersion: to display the current version.

Create a virtual environment

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.

List virtual environments

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

Activate a virtual environment

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

Leave from a virtual environment

Just type deactivate as usual (Python default).

Todo

  • Activate the autocompletion
  • Set the virtualenvwrapper options into system environment variables (see the main project)

About

A mimic of the VirtualEnvWrapper project but with Powershell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PowerShell 100.0%