DEV Community

hub
hub

Posted on • Updated on

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?

Python 3.3 includes in its standard library the new package venv. What does it do, and how does it differ from all the other packages that match the regex (py)?(v|virtual|pip)?env?

Quote: from stack overflow

This is my personal recommendation for beginners: start by learning virtualenv and pip, tools which work with both Python 2 and 3 and in a variety of situations, and pick up other tools once you start needing them.

Now on to answer the question: what is the difference between these similarly named things: venv, virtualenv, etc?

PyPI packages not in the standard library:
virtualenv is a very popular tool that creates isolated Python environments for Python libraries. If you're not familiar with this tool, I highly recommend learning it, as it is a very useful tool.

It works by installing a bunch of files in a directory (eg: env/), and then modifying the PATH environment variable to prefix it with a custom bin directory (eg: env/bin/). An exact copy of the python or python3 binary is placed in this directory, but Python is programmed to look for libraries relative to its path first, in the environment directory. It's not part of Python's standard library, but is officially blessed by the PyPA (Python Packaging Authority). Once activated, you can install packages in the virtual environment using pip.

pyenv is used to isolate Python versions. For example, you may want to test your code against Python 2.7, 3.6, 3.7 and 3.8, so you'll need a way to switch between them. Once activated, it prefixes the PATH environment variable with ~/.pyenv/shims, where there are special files matching the Python commands (python, pip). These are not copies of the Python-shipped commands; they are special scripts that decide on the fly which version of Python to run based on the PYENV_VERSION environment variable, or the .python-version file, or the ~/.pyenv/version file. pyenv also makes the process of downloading and installing multiple Python versions easier, using the command pyenv install.

pyenv-virtualenv is a plugin for pyenv by the same author as pyenv, to allow you to use pyenv and virtualenv at the same time conveniently. However, if you're using Python 3.3 or later, pyenv-virtualenv will try to run python -m venv if it is available, instead of virtualenv. You can use virtualenv and pyenv together without pyenv-virtualenv, if you don't want the convenience features.

virtualenvwrapper is a set of extensions to virtualenv (see docs). It gives you commands like mkvirtualenv, lssitepackages, and especially workon for switching between different virtualenv directories. This tool is especially useful if you want multiple virtualenv directories.

pyenv-virtualenvwrapper is a plugin for pyenv by the same author as pyenv, to conveniently integrate virtualenvwrapper into pyenv.

pipenv aims to combine Pipfile, pip and virtualenv into one command on the command-line. The virtualenv directory typically gets placed in ~/.local/share/virtualenvs/XXX, with XXX being a hash of the path of the project directory. This is different from virtualenv, where the directory is typically in the current working directory. pipenv is meant to be used when developing Python applications (as opposed to libraries). There are alternatives to pipenv, such as poetry, which I won't list here since this question is only about the packages that are similarly named.

virtuelle Umgebungen und Paketverwaltung mit pip - PyTuDe - Python Tutorial auf Deutsch

[martin@martinsendeavour dev]$ -m venv tutorial-env
bash: -m: Kommando nicht gefunden.
[martin@martinsendeavour dev]$ python3 -m venv tutorial-env
[martin@martinsendeavour dev]$ ource tutorial-env/bin/activate
bash: ource: Kommando nicht gefunden.
[martin@martinsendeavour dev]$ source tutorial-env/bin/activate
(tutorial-env) [martin@martinsendeavour dev]$

hmm - ich glaube dass das so insges. etwas besser ist... °?

vgl. https://forum.endeavouros.com/t/steps-to-install-and-setup-vscode-on-endeavouros/38375

cf. https://code.visualstudio.com/docs/python/

etc, cf. https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments 6
wobei ich ja die Environment-Geschichte ja shcon hab.

und jetzt denke ich - VSCode einach draufbauen zu können auf den Rechner.

https://pytude.readthedocs.io/de/latest/venv/

https://forum.endeavouros.com/t/steps-to-install-and-setup-vscode-on-endeavouros/38375

cf. https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments 6

zu pip venv usw. usf https://stackoverflow.com/q/41573587/9283927

`
cd

python -m venv venv

ls -la

source venv/bin/activate

pip -V

`

und :

[_bob_@\_bob\_sendeavour digital_innovation_hub]$ cd
[_bob_@\_bob\_sendeavour ~]$ ^[[200~python -m venv dev_environment
bash: $'\E[200~python': Kommando nicht gefunden.
[_bob_@\_bob\_sendeavour ~]$ ^[[200~python -m venv dev_environment
bash: $'\E[200~python': Kommando nicht gefunden.
[_bob_@\_bob\_sendeavour ~]$ python -m venv devenv
[_bob_@\_bob\_sendeavour ~]$ ls -la
insgesamt 108
drwx------ 21 _bob_ _bob_ 4096 24. Jan 13:19 .
drwxr-xr-x 3 root root 4096 24. Feb 2023 ..
-rw------- 1 _bob_ _bob_ 1983 14. Jan 21:49 .bash_history
-rw-r--r-- 1 _bob_ _bob_ 21 2. Feb 2023 .bash_logout
-rw-r--r-- 1 _bob_ _bob_ 57 2. Feb 2023 .bash_profile
-rwxr-xr-x 1 _bob_ _bob_ 2691 8. Feb 2023 .bashrc
drwxr-xr-x 4 _bob_ _bob_ 4096 22. Mär 2023 Bilder
drwxr-xr-x 26 _bob_ _bob_ 4096 24. Jan 10:04 .cache
drwxr-xr-x 24 _bob_ _bob_ 4096 24. Jan 12:31 .config
drwxr-xr-x 5 _bob_ _bob_ 4096 24. Jan 12:33 dev
drwxr-xr-x 5 _bob_ _bob_ 4096 24. Jan 13:19 devenv
drwxr-xr-x 8 _bob_ _bob_ 4096 15. Jan 17:51 Dokumente
drwxr-xr-x 2 _bob_ _bob_ 4096 15. Jan 17:41 Downloads
drwx------ 2 _bob_ _bob_ 4096 17. Mär 2023 .gnupg
-rw-r--r-- 1 _bob_ _bob_ 265 24. Jan 09:23 .gtkrc-2.0
drwxr-xr-x 4 _bob_ _bob_ 4096 24. Feb 2023 .local
drwx------ 4 _bob_ _bob_ 4096 28. Feb 2023 .mozilla
drwxr-xr-x 2 _bob_ _bob_ 4096 24. Feb 2023 Musik
drwxr-xr-x 2 _bob_ _bob_ 4096 24. Feb 2023 Öffentlich
drwx------ 3 _bob_ _bob_ 4096 28. Feb 2023 .pki
drwxr-xr-x 2 _bob_ _bob_ 4096 24. Feb 2023 Schreibtisch
drwxr-xr-x 5 _bob_ _bob_ 4096 13. Mär 2023 .venv
drwxr-xr-x 6 _bob_ _bob_ 4096 24. Jan 10:07 venv
drwxr-xr-x 2 _bob_ _bob_ 4096 24. Feb 2023 Videos
drwxr-xr-x 2 _bob_ _bob_ 4096 24. Feb 2023 Vorlagen
drwxr-xr-x 3 _bob_ _bob_ 4096 13. Mär 2023 .vscode-oss
-rw------- 1 _bob_ _bob_ 61 27. Jul 10:40 .Xauthority
[_bob_@\_bob\_sendeavour ~]$ source venv/bin/activate
(venv) [_bob_@\_bob\_sendeavour ~]$ pip -V
pip 23.2.1 from /home/_bob_/venv/lib/python3.11/site-packages/pip (python 3.11)
(venv) [_bob_@\_bob\_sendeavour ~]$

vgl. auch corey schaefer; Python Tutorial: VENV (Mac & Linux) - How to Use Virtual Environments with the Built-In venv Module
https://www.youtube.com/watch?v=Kg1Yvry_Ydk&t=78s

Top comments (0)