A beginner's guide on effectively managing Python virtual environments using different tools in Python ecosystem.
Popular Python virtual environment management options:
- [1] venv
- [2] virtualenv
- [3] virtualenvwrapper
- [4] pipenv
- [5] poetry
- [6] pyenv-virtualenv
- [7] conda
- [8] hatch
- [9] pdm
- [10] pew
- [11] tox
- [12] nox
- [13] rye
It's glad that the Python ecosystem offers numerous options for managing virtual environments and dependencies. Yet, for beginners, this abundance may lead to the common question: Which one should I choose? In this section, I aim to share my experience and opinions to guide beginners to make right choices.
None could be more easy than venv, as it is a Python (>=3.3) built-in module, nonthing needs to be installed, just running command python -m venv to use it. If you simply want to create a virtual environment for your Python project, and don't want to install third party packages for this purpose, then go for with venv. As a beginner, you could start with venv and pip, where use venv to create virtual environment, and use pip to manage environment dependencies.
Please notice that venv does not support older versions of Python (<3.3 or 2.x), you will need to a third-party tool to help in this case.
virtualenv instead is an independent library to create isolated Python environments, and a subset of virtualenv has been integrated into the standard library under the venv module. If you try to use a third-party library to manage Pyton virtual environments, then I highly recommend learning and trying with it. Compared to venv, here are some advantages of virtualenv:
- it is faster
- it is extendable
- it can create environments for any python versions.
- it is upgrade-able via
pip. - it has rich programmatic API.
Besides, several other popular tools like virtualenvwrapper, pew, tox and nox are depending on virtualenv and build abstractions on top of it.
By the way, with virtualenv, you also need to use pip to manage environment dependencies.
virtualenv wrappers provide convenient commands to help create and delete virtual environments, otherwise managing the development workflow and making it easier to work on multiple projects without dependency conflicts.
virtualenvwrapper and pew are popular wrappers built on top of virtualenv, and both of the are great choices. The workon command is really convenient to help switch environments when working on multiple Python projects with different dependencies.
For virtualenvwrapper:
virtualenvwrapperautomated tests run under these shells on OS X and Linux with bash and zsh.- Windows users need to usea separately distributed re-implementation iwth
virtualenvwrapper-win. virtualenvwrapperis a set of shell functions defined in Bourne shell compatible syntax.
For pew users:
- It would luanch a subshell when activating the environment.
- It is completely shell-agnostic and thus works on bash, zsh, fish, powershell, etc.
- It is invoked starting with
pewin commands.
As a zsh user under both Ubuntu and MacOS, I personally like the command style and syntax of virtualenvwrapper, like mkvirtualenv, rmvirtualenv. And I have been using it for years, there is no reason for me to switch from virtualenvwrapper to pew yet. But again, both of them are great, the choice depends on your work environment and personal flavor.
[In progress...]
If you have any question about this opinionated list, do not hesitate to contact me @jgujerry on X (Twitter) or open an issue on GitHub.
This project is released under MIT License