virtualenvwrapper is a set of shell scripts that enhance the functionality of virtualenv, a tool for creating isolated Python environments. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.
Install virtualenv and virtualenvwrapper using pip
$ pip install --user virtualenv virtualenvwrapperSetup your shell by adding the following lines into your shell profile (e.g. .bashrc, or .zshrc)
$ export WORKON_HOME=$HOME/.virtualenvs
$ export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
$ export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
$ export VIRTUALENVWRAPPER_SCRIPT=~/.local/bin/virtualenvwrapper.sh
$ source ~/.local/bin/virtualenvwrapper.shPlease check your installation path and configure Python version, virtualenv, virtualenvwrapper.sh properly.
Please check the --help document,
$ mkvirtualenv --helpHere we only provide the basic usage command, supposing we are creating a virtual environment named testenv.
$ mkdirvirtualenv testenvTo duplicate an existing virtual environment,
$ cpvirtualenv <env-name> testenvWhat's inside the virtual environment?
$ cdvirtualenv
$ lssitepackages
$ cdsitepackagesYou can easily tell what the command is trying to do from the command name.
If run workon command without any arguments, it will list all virtual environments.
$ workonAnother command to list the virtual environments is
$ lsvirtualenvTo activate the virtual environment, run the following command
$ workon testenvTo install or uninstall a single package, run
$ pip install <package-name>To install a list of Python packages in requirements.txt, run
$ pip install -r requirements.txtTo uninstall the Python package,
$ pip uninstall <package-name>If you try to remove all of the installed third-party packages in current virtual environment, run this command
$ wipeenvRun the following command to deactivate the virtual environment,
$ deactivateRun the following command to remove the virtual environment,
$ rmvirtualenv testenvIf there are multiple Python versions installed on your system, then you could specify a version with -p/--python when creating the virtual environment.
$ mkvirtualenv -p python3.10 testenv10$ mkvirtualenv -p python3.11 testenv11$ mkvirtualenv -p python3.12 testenv12For more details about virtialenvwrapper, please refer to the official documentation.
Happy coding!