Ubuntu: What are the differences/similarities between multiple python package management?



Question:

Python seems to have multiple package management system that leads to confusions and conflicts when used in parallel. I would like some guidance in how to operate with these tools to get the best system state.

Here are my questions:

  • There are so many package installing tools when it comes to python: apt-get, pip, easy_install, conda and the python3 version of those. Could somebody explain when one should use the particular tools and the concept of those tools work together? I would even appreciate it if someone could give me a link to an article which actually goes through each of these systems in detail, compares them, and highlights the differences between them.
  • Would installing and running python stuff using anaconda take care of the headache of using multiple python package tools?
  • If the python packages that anaconda installs are already present in the system how those two coordinate when we use them?


Solution:1

The main similarity between apt/apt-get, pip, easy_install and conda is that they are package managers; there are more differences between them than there are similarities.

Let's start with easy things first. Never use easy_install over pip, and the reasons for this are eloquently explained in the various highly upvoted answers to https://stackoverflow.com/q/3220404/486919. In short, easy_install is obsolete and pip is always to be preferred.

apt/apt-get

You use apt or apt-get to install at the system/global level Ubuntu packages, including the ones for Python, found in APT repositories. You need to run this command with sudo. In the Ubuntu repositories, the names for Python 2 packages are prepended with python while that for Python 3 are prepended with python3, so it is clear what packages you need to install depending on what version of the Python interpreter you intend to use. Some examples include python-numpy and python3-numpy.

pip

pip stands for "Pip Installs Packages" or "Pip Installs Python", which is a recursive acronym. As the name suggests, you use pip to install Python packages only. At the system/global level, you can install pip for Python 2 using sudo apt install python-pip and for Python 3 using sudo apt install python3-pip. In Ubuntu, pip install defaults to pip install --user. The same happens if you replace pip with pip3. This means that Python packages are by default installed on a per-user basis and not at the system/global level. This is a good thing because there are no good reasons to make Python packages available to all users by default. You can install them globally by running the command with sudo, but as I have explained at https://askubuntu.com/a/802594/15003, this is a security risk and should not be done.

The best way to manage Python dependencies is to use virtual environments. An example of this is virtualenv, which can be installed using sudo apt install virtualenv. I wrote a short answer about this at https://askubuntu.com/a/786625/15003 but there are other very good answers to the question that you can read about.

conda

conda is a package manager that also allows you to create virtual environments, so it is somewhat like pip + virtualenv. According to https://stackoverflow.com/a/20994790/486919, conda can also "handle library dependencies outside of the Python packages as well as the Python packages themselves". I personally don't use Anaconda/Conda on my Ubuntu machine since pip and virtualenv are good enough for my needs, but you should definitely check out conda.


Solution:2

There are so many package installing tools when it comes to python: apt-get, pip, easy_install, conda and the python3 version of those. Could somebody explain when one should use the particular tools and the concept of those tools work together? I would even appreciate it if someone could give me a link to an article which actually goes through each of these systems in detail, compares them, and highlights the differences between them.

apt-get

It is not a Python package manager, it is the package manager for Ubuntu. You use it to install Ubuntu software.

As to why it has Python packages inside it, Ubuntu packages most Python modules like this: python-modulename or python3-modulename. These Ubuntu Python modules are outdated. Use pip (or pip3).

pip

It is the standard Python package manager. When in doubt, use this.

conda

It is a Python package manager plus an environment manager. That is, it builds you an isolated, fresh Python environment, allowing you to freeze specific modules at a version while not affecting system Python, etc.

Would installing and running python stuff anaconda take care of the headache of using multiple python package tools?

Firstly, it is not a headache. Just

$ pip install modulename  

(or pip3 for Python 3, since 2 and 3 are hugely incompatible.)

Secondly, conda is yet another package manager for Python, which has (I think) fewer packages than pip and is only good for freezing specific versions of system libraries, Python modules etc.

If the python packages that anaconda installs are already present in the system how those two coordinate when we use them?

conda overwrites already-present packages.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »