ChatGPT解决这个技术问题 Extra ChatGPT

What is the difference between pyenv, virtualenv, anaconda?

I am a ruby programmer trying to learn python. I am pretty familiar with pyenv since it is like a copy and paste from rbenv. Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive parts of system.

I suppose every python installation comes with pip package. What I still don't understand is, there are many good python libs out there that suggest to use this virtualenv and anaconda. I can even find a virtualenv plugin for pyenv.

Now I am getting confused with the purpose of these two pyenv and virtualenv. worse inside pyenv there is a virtualenv plugin.

My questions are:

what is the difference between pyenv and virtualenv?

Is there any difference in using pip command inside both pyenv and virtualenv?

what does this pyenv virutalenv do?

Your explanation with example will be highly appreciated.


G
Gh0sT

Edit: It's worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic.

pip: the Python Package Manager.

You might think of pip as the python equivalent of the ruby gem command

pip is not included with python by default.

You may install Python using homebrew, which will install pip automatically: brew install python

The final version of OSX did not include pip by default. To add pip to your mac system's version of python, you can sudo easy_install pip

You can find and publish python packages using PyPI: The Python Package Index

The requirements.txt file is comparable to the ruby gemfile

To create a requirements text file, pip freeze > requirements.txt

Note, at this point, we have python installed on our system, and we have created a requirements.txt file that outlines all of the python packages that have been installed on your system.

pyenv: Python Version Manager

From the docs: pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.

Many folks hesitate to use python3.

If you need to use different versions of python, pyenv lets you manage this easily.

virtualenv: Python Environment Manager.

From the docs: The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

To create a virtualenv, simply invoke virtualenv ENV, where ENV is is a directory to place the new virtual environment.

To initialize the virtualenv, you need to source ENV/bin/activate. To stop using, simply call deactivate.

Once you activate the virtualenv, you might install all of a workspace's package requirements by running pip install -r against the project's requirements.txt file.

Anaconda: Package Manager + Environment Manager + Additional Scientific Libraries.

From the docs: Anaconda 4.2.0 includes an easy installation of Python (2.7.12, 3.4.5, and/or 3.5.2) and updates of over 100 pre-built and tested scientific and analytic Python packages that include NumPy, Pandas, SciPy, Matplotlib, and IPython, with over 620 more packages available via a simple conda install

As a web developer, I haven't used Anaconda. It's ~3GB including all the packages.

There is a slimmed down miniconda version, which seems like it could be a more simple option than using pip + virtualenv, although I don't have experience using it personally.

While conda allows you to install packages, these packages are separate than PyPI packages, so you may still need to use pip additionally depending on the types of packages you need to install.

See also:

conda vs pip vs virtualenv (section in documentation from anaconda)

the difference between pip and conda (stackoverflow)

the relationship between virtualenv and pyenv (stackoverflow)


This could probably use a refresh now, c.f. stackoverflow.com/a/49084152/14420
Could this be updated to included to pipenv as it currently seems to be the officially recommended Python packaging tool from Python.org ?
What's the issue with installing a mere 3GB worth of libraries? You wouldn't want to deploy all those libraries, but just because you have 3GB worth of libraries installed doesn't mean you need to deploy all of it. And that's a tiny amount of hard drive space these days. I currently use an anaconda installation and they I manage my environments with venv, but I was considering whether to use conda for my virtual environments too (I don't think I will - venv seems like a smoother workflow to me).
@David I'm a bit late, but can you expand on venv seems like a smoother workflow to me?
@Aditya You have a very good point. I was comfortable with venv, is the main reason. But I've since switched over to using conda to manage my packages, and I like it.
c
channa ly

Simple analogy:

pyenv ~ rbenv

pip ~ bundler

virtual env ~ gemset in rvm. This can be managed by bundler directly without gemset.

Since I use python3 I prefer the python3 built-in virtual environment named venv. venv is simple and easy to use. I would recommend you to read its official docs. The doc is short and concise.

In ruby, we don't really need a virtual environment because the bundler takes care of it. Both virtual env and bundler are great, however, they have different solutions to solve the same problem.


pipenv is similar to bundler. pip to gem.
J
Jorge Tovar

Simple explanation: https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands

If you have used pip and virtualenv in the past, you can use conda to perform all of the same operations.

Pip is a package manager

virtualenv is an environment manager

Conda is both