Ubuntu – easy_install/pip or apt-get

aptpython

As noted in the Ubuntu wiki page on Rails it is recommended that gems manages your Rails/Ruby dependencies.

What is the best practise with Python packages like Django? Should I install them through apt-get or should I let easy_install/pip fetch them from PyPi?

Best Answer

There are several arguments:

  1. Use Repositories/PPAs because they will keep you both stable and up to date with security fixes.

    This is mostly true. If, for example, you install python-django as I have, you get security updates. This is good because you only have to keep on top of apt but you still have to test things before you push updates (although testing should be fine each time).

    You could argue that if you used pip, you might never check for updates.

  2. Use pip so you can use the proper "stable" versions.

    There's no doubt about it: The repos lag behind the real world. Django is 2.0 but the repos for the LTS version of Ubuntu (that a lot of people stick with for servers) you only get 1.8 on Ubuntu 16.4 lts with Python 2 but still get security updates on it.

    pip gives you the latest all the time. You just have to update them yourself.

  3. Upgrading a repo-used Python install can be a nightmare

    When you dist-upgrade Ubuntu to the next version, it upgrades a lot of packages. Lots of things change. I know in Django this means you have to take care to watch out for code-incompatibilities, deprecations... But the same applies to all other Python code.

    The same is true for pip but with pip you get to do one thing at a time. You know what causes the problems so you know where to look to find the fix.

  4. pip+virtualenv lets you keep things separate

    virtualenv lets you have portable, little Python environments. This allows you to have several different Python environments running alongside each other on the same machine.

    The obvious boon seems to be for maintenance as you can manage the environment in the same way as you manage the code. Even store the environment in the VCS too... but you should remember that having twelve different virtualenvs means twelve environments you need to check on and update.


Edit: After a horrible series of upgrades on a server to get it from Lucid to Precise, I've switched from a mixed Apt+pip (nr 1 and 2) to a pure pip+virtualenv (nr. 4) situation. Instead of having one virtualenv per site, I've got one shared one between a dozen-or-so sites. This is working for now.

I've also had to write a little script that checks the status of packages installed with pip. If there are updates I have to apply them manually (which is good because I test them locally, in a local virtualenv). This is all still a little more painful than it was originally but much better in the long run.

Related Question