What is the difference between pyenv, virtualenv, anaconda?
Asked Answered
D

3

266

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.

Drizzle answered 6/7, 2016 at 6:31 Comment(2)
related: #29950800Helvetii
see this question : relationship between virtualenv and pyenvLasonde
S
255

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 + Python Version Manager + Environment Manager + Additional Scientific Libraries.

  • **Anaconda is a commercial distribution of Python with the most popular python libraries, you are not permitted to use Anaconda in an organisation with more than 200 employees.
  • 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 <packagename>
  • 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:

Sklar answered 8/10, 2016 at 2:22 Comment(8)
This could probably use a refresh now, c.f. https://mcmap.net/q/99189/-does-conda-replace-the-need-for-virtualenvBandwidth
Could this be updated to included to pipenv as it currently seems to be the officially recommended Python packaging tool from Python.org ?Sanfred
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).Euplastic
@Euplastic I'm a bit late, but can you expand on venv seems like a smoother workflow to me?Liverpool
@Euplastic Personally speaking, though I agree that 3GB is not big nowadays, there is always something to be said about a minimalistic experience. To your second, why use venv and install conda at the same time? Doesn't that render conda pointless?Mors
@Mors I think I prefer venv because it uses less of a global structure and more of a local folder structure, plus it's reference more frequently in other sources. I like downloading a conda distribution though because it comes pre-installed with many of the libraries that I use.Euplastic
@Liverpool see my comment above (sorry I just saw this)Euplastic
@Mors 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.Euplastic
D
10

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.

Drizzle answered 1/6, 2020 at 12:18 Comment(1)
pipenv is similar to bundler. pip to gem.Vasodilator
A
5

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
Anthropogeography answered 28/4, 2022 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.