|
|
Log in / Subscribe / Register

Distributions wrestle with pip

By Jake Edge
March 26, 2014

One of the headline features for Python 3.4 was the inclusion of the pip Python package installer by default. But now that 3.4 is out, distributions are finding that the interactions between Python's pip and system-installed pip programs were not completely thought out. Complicating things further is the virtualenv program that is used to create a private Python environment for development and other purposes.

Barry Warsaw sounded the alarm in a long message to the debian-python mailing list. There is an ensurepip program that is shipped with Python 3.4, but disabled in Debian, that will bootstrap pip for a Python installation. Pip is released on its own schedule, separate from that of the main language and standard library. ensurepip is used to install (or upgrade) the pip package and, as its name implies, ensure that pip is available. Debian has its own .deb-based pip package, though, so ensurepip is not needed for the distribution as package dependencies will pull in pip.

Except that it is needed. When creating a virtual environment using the pyvenv program—which is shipped with Python to create virtual environments—on Debian, the lack of an installed ensurepip causes a failure. To further complicate an already murky situation, the virtualenv command from the Debian python-virtualenv package works just fine. Virtual environments create a Python installation that is entirely separate from any other Python installation on the system. They can be used to simultaneously run multiple versions of Python (2.x and 3.x, say) or to run programs using different library versions (multiple versions of Django, for example).

Debian is not the only distribution struggling with pip for Python 3.4. Fedora has also encountered it. It has also been discussed before by both distributions (and presumably others).

The idea behind bundling pip comes from Python enhancement proposal (PEP) 453. It is really aimed at users of operating systems that don't have the equivalent of a distribution package manager (e.g. Windows or OS X) to make it easier for those users to access packages outside of the standard library at the Python package index (PyPI). But even a distribution with as many packages as Debian has does not package all of those available at PyPI, so there is still a need for pip, even on Linux distributions.

But it is clear from the threads that pip is not universally admired. One of the problems with it was raised by Scott Kitterman back in September: there is no package validation when using pip. There are plans to add that feature, but that is not sufficient for some. As Kitterman put it: "I think that introducing a package download mechanism that is not cryptographically secured with a promise to later insecurely update the mechanism to have security is crazy talk."

In addition, pip does not play well with Python packages that are installed using the standard distribution package manager. It acts as if it owns the whole Python installation and will just overwrite files in the site-packages directory when run as root. It clearly shows its non-Linux bias, which is irritating to some and can lead to unexpected results. For that reason, distributions generally try to restrict pip to either not run as root or to only affect the user-specific package installation (in ~/.local).

Part of the solution may lie in finding a foolproof way to determine whether Python is running in a virtual environment or not. Warsaw outlined several tests that can be made to try to figure that out (and to figure which type of virtual environment it is). He suggested incorporating that into Debian's version of ensurepip so that it would be available for use in environments created with pyvenv, but not globally (which would allow users to run pip as root and potentially step on files installed by Apt and friends).

Fedora has taken a different approach, as described by Bohuslav Kabrda. By using the custom rewheel program, Python packages in the Wheel format (which is how the bundled pip is delivered) can be unpacked, modified for Fedora, then repacked into a new Wheel file. The ensurepip program can call rewheel to install pip properly for Fedora.

Though rewheel is not distribution-specific, Warsaw was not particularly interested in that approach for Debian (or, especially, Ubuntu, where the pip package lives in Universe rather than the main repository). It would introduce a circular dependency for Debian and cross-repository dependency for Ubuntu, Warsaw noted. But Fedora is also preparing for a switch to Python 3 as its default in the not too distant future, so the rewheel plan is expedient, Kabrda said.

There is clearly something of an impedance mismatch between Linux distributions and languages (or other systems) that have their own idea of how packages or add-ons should be installed. Making pip play more nicely with distribution package managers would go a long way toward solving the problem for Python, at least. There are movements in that direction, but we aren't there yet.

[ Thanks to Olav Vitters for a heads-up about this issue. ]


to post comments

Distributions wrestle with pip

Posted Mar 27, 2014 13:46 UTC (Thu) by drag (guest, #31333) [Link]

For the major scripting languages that I use I avoid distribution package management as much as possible. The versions shipped by distributions are very often not the versions I need.

I'll use the distribution provided binaries for bootstrapping the environments, but otherwise I avoid them.

This includes python, perl, and elisp for emacs.

Distributions wrestle with pip

Posted Mar 27, 2014 18:38 UTC (Thu) by debacle (subscriber, #7114) [Link] (5 responses)

I avoid any non-distribution package managers as much as possible, i.e. practically completely. This includes Firefox addons that are not packaged for my distribution, Emacs modes, Python modules, ruby, node, perl, Gnome apps, etc.

While using pip inside a virtualenv has some benefits (you can easily test software with different versions of some modules, even non-packaged ones), the disadvantages are mainly related to deployment:

  1. It is not easily possible to reproduce the "packaging state" of a machine. dpkg --get-selections/--set-selections does not work anymore.
  2. Tools designed to check the system state in respect to the official package manager, such as debsums, don't work for software installed outside it. Alternative tools do not yet exist to my knowledge.
  3. If you install software outside of a virtualenv, i.e. in /usr/local/, you can break unrelated software easily without knowing.
  4. You don't have a single point of contact for bug reports, such as bugs.debian.org, but many different ones - or none.
  5. Dependencies that cannot fulfilled within the world of one system such as Emacs or Python are out of scope for such package managers. apt-get etc. don't have a problem, if a program written in Perl depends on another one written in Ruby.
  6. I can't trust the download. There is no digital signature in most of the specialised package managers.

In my projects developers are forced to use only Python modules that are in Debian stable (or testing, depending on the time frame of the project) - or they have to package or backport it. pip is only allowed for experiments, but not for any deployment.

Distributions wrestle with pip

Posted Mar 27, 2014 22:42 UTC (Thu) by mgedmin (guest, #34497) [Link] (3 responses)

pip downloads the packages over HTTPS, and also checks the SSL certificate, so you can be sure you're getting the bits that were uploaded to PyPI.

(Unless the NSA subverts a CA and MITMs you.)

Distributions wrestle with pip

Posted Mar 28, 2014 12:51 UTC (Fri) by Funcan (guest, #44209) [Link]

And what is the security for uploading to PyPy?

Distributions wrestle with pip

Posted Mar 28, 2014 13:25 UTC (Fri) by cortana (subscriber, #24596) [Link] (1 responses)

This is not sufficient. Pip is useless to me until it checks the hashes of the packages actually downloaded against something signed by a trusted party. This is the model used by Debian and, I assume, most other distributions.

This is not a problem unique to Pip. I've no idea how/if other tools like gem, maven, ivy, cpan, etc., verify what they download, and the fact that most developers are entirely unconcerned with this state of affairs terrifies me.

Distributions wrestle with pip

Posted Mar 28, 2014 14:45 UTC (Fri) by kfiles (subscriber, #11628) [Link]

Maven and Ivy verify against the SHA1 hashes stored in the repository, but these are not signed. So you're vulnerable to a compromised central repository instead a compromised developer's build/signing server.

CPAN doesn't store hashes, AFAIK; I think gems are signed, but I'm not sure.

In other words, it's a crapshoot out there. Personally, I'm OK with verifying hashes on 3rd-party libraries as a reasonable tradeoff between security and usability. Managing the thousands of keys required to verify all the libraries published in Maven would drive me crazy, and there's never going to be a central authority for all of that software, as there is for a Linux distribution.

Distributions wrestle with pip

Posted Mar 28, 2014 14:59 UTC (Fri) by debacle (subscriber, #7114) [Link]

I forgot two disadvantages of non-distribution package management, again related to deployment:

  1. (= 7.) Non-distribution package managers are usually limited to HTTP(S) downloads. Distribution package managers allow offline installation from any kind of media, such as SD cards, hard disks, DVDs.
  2. (= 8.) To have your own, private, trusted Emacs package, PyPI, gems, etc. server, you need to duplicate, triplicate the effort when you already have your own package repository, e.g. easily created with reprepro for apt.

The excuse of using pip and friends outside a virtualenv is Windows, an operating system without usable package management to my rusty knowledge. Linux distribution don't suffer from this problem.

Distributions wrestle with pip

Posted Mar 27, 2014 20:23 UTC (Thu) by rriggs (guest, #11598) [Link] (2 responses)

The problems seen with pip occur with Perl CPAN, Eclipse, R (CRAN), etc. Why the uproar over pip?

Distributions wrestle with pip

Posted Mar 27, 2014 22:17 UTC (Thu) by dlang (guest, #313) [Link] (1 responses)

because the behaviour of pip is new.

new changes are always disliked more than equivalent behaviour that's long established.

Distributions wrestle with pip

Posted Apr 18, 2014 5:08 UTC (Fri) by Kamilion (subscriber, #42576) [Link]

When did pip's behavior change? I've been using it for at least two to three years now. I don't recall any real changes (user facing or policy-wise) from easy_install/setuptools.

And what behavior of pip changed? (I am genuinely curious, since in the past, I have had to convince pip to update the version of pip that apt installed in site-packages because it did not support the --pre flag.)

Or is it simply because pip has now landed in what amounts to be python's stdlib? Is that the change in behavior you allude to?


Copyright © 2014, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds