pyvenvwrapper is a small and lightweight set of Bash script functions, that enhance the use of venv module for management of virtual environments.
pyvenvwrapper is a small and lightweight set of Bash script functions, that enhance the use of Python standard library venv module for management of virtual environments. Between Python 3.2 and Python 3.6 venv module was wrapped in a pyvenv script, that is now officially deprecated in favor of direct usage of venv module. pyvenvwrapper functions allow to create and manipulate virtual environments and corresponding projet folders in a convenient way using only their names. Additional feature is automatic activation/deactivation of virtual environment when changing current working directory in the shell. Since venv and virtualenv use similar technics for virtual environments, pyvenvwrapper can be used for both, though main aim is venv.
pyvenvwrapper can be used to manage virtual environments and corresponding project folders or only virtual environments. In former case it assumes that the same name is used for virtual environment folder and the project folder which uses this virtual environment. The directories containing this folders are configured using special variables.
The idea to create pyvenvwrapper is inspired by using virtualenvwrapper, which at that moment didn’t have support for pyvenv and venv virtual environment management. pyvenvwrapper code is in no way related to virtualenvwrapper code.
Full pyvenvwrapper documentation is available online at readthedocs.org.
pyvenvwrapper functions are written and tested for Bash shell, however they might work with other Bash-like shells. pyvenvwrapper is pure shell script with calls to common system tools, so it doesn’t care much on what Python version is used, therefore it should work with any Python 2 or Python 3 version. Some features will require ‘pip’. pyvenvwrapper originally was intended to be used with ‘pyvenv’ tool (‘venv’ module in Python standard library), but it supports ‘virtualenv’ tool too.
To install pyvenvwrapper:
Run ‘pip install pyvenvwrapper’, this will download and install required files on your machine.
Run ‘pyvenvwrapper_enable’, this will enable pyvenvwrapper for current user by adding the following lines to user’s .bashrc file:
source [path_to_pyvenvwrapper]/pyvenvwrapper_settings source [path_to_pyvenvwrapper]/pyvenvwrapper
There’s also ‘pyvenvwrapper_disable’ command, which disables pyvenvwrapper for current user by removing those lines.
Reboot your shell or run ‘source ~/.bashrc’.
Run ‘pyvenvwrapper’ to see available commands and start using pyvenvwrapper or see Settings to customize its behavior first.
See additional details on installation in the documentation.
pyvenvwrapper includes the following functions, that are used as common commands in Bash:
mkvenv - creates virtual environment and optionally related project folder;
workon - activates existing virtual environment and optionally changes current working directory to related project folder;
deact - deactivates currently active virtual environment and optionally changes current working directory back to the one used before this virtual environment activation;
lsvenv - prints existing virtual environments’ names, or if used with virtual environment name as argument prints packages installed in it;
cdvenv - changes current working directory to specified virtual environments directory, or related project directory depending on provided options;
cpvenv - copies existing virtual environment with new name and optionally related project folder;
rmvenv - deletes existing virtual environment and optionally related project folder.
All commands support auto-completion with existing virtual environment names, and display usage and possible options when called with -h or –help options.
All commands can have added behavior before and/or after execution via custom scripts that can be assigned to special hook variables. See “Hooks” section in docs for details.
pyvenvwrapper uses the following variables for settings (provided with defaults), which you can redefine in pyvenvwrapper_settings file in pyvenvwrapper package or in the end of user’s .bashrc file:
PYVENVWRAPPER_ENV_DIR=~/.virtualenvs - directory to keep virtula environment folders, the only mandatory setting.
PYVENVWRAPPER_PROJ_DIR=~/projects - directory to keep project folders;
PYVENVWRAPPER_CD_ON_WORKON=true - enables/disables automatic current working directory change to related project folder after virtual environment activation using workon command;
PYVENVWRAPPER_CD_ON_DEACT=true - enables/disables automatic current working directory change after deact command execution back to the one used before virtual environment activation;
PYVENVWRAPPER_ACTIVATE_ON_CD=true - enables/disables automatic activation of virtual environment when changing current working directory using cd/popd/pushd command to any directory related to existing virtual environment or its corresponding project, and virtual environment deactivation when exiting it. This is made possible via redefining Bash’s cd, popd, pushd built-ins, thought it’s done in a transparent fashion and shouldn’t affect their use in other contexts.
Any questions or issues can be reported via GitHub Issues.
- Added support for creation of virtual environments using venv module (python -m venv). It is now preferred by default with a fallback to pyvenv and virtualenv. Using venv directly is officially recommended for creating virtual environments since Python 3.5. pyvenv script is officially deprecated in Python 3.6.
- Added new option -b/–python to mkvenv command, that allows to specify which Python interpreter executable to use for new virtual environment. This option works with venv and virtualenv.
- Initial version with all the main features.
The MIT License (MIT)
Copyright (c) 2016 Nikita Solovyev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pyvenvwrapper-1.0.0-py2.py3-none-any.whl (24.5 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size pyvenvwrapper-1.0.0.tar.gz (6.1 MB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for pyvenvwrapper-1.0.0-py2.py3-none-any.whl