Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I install Python packages into `~/.local`?

Tags:

python

Background

  1. I don't develop using OS X's system provided Python versions (on OS X 10.6 that's Python 2.5.4 and 2.6.1).
  2. I don't install anything in the site-packages directory for the OS provided versions of Python. (The only exception is Mercurial installed from a binary package, which installs two packages in the Python 2.6.1 site-packages directory.)
  3. I installed three versions of Python, all using the Mac OS X installer disk image:
    1. Python 2.6.6
    2. Python 2.7
    3. Python 3.1.2
  4. I don't like polluting the site-packages directory for my Python installations. So I only install the following five base packages in the site-packages directory. For the actual method/commands used to install these, see SO Question 4324558.
    1. setuptools/ez_setup
    2. distribute
    3. pip
    4. virtualenv
    5. virtualenvwrapper
  5. All other packages are installed in virtualenvs.
  6. I am the only user of this MacBook.

Questions

  1. Given the above background, why should I install the five base packages in ~/.local? Since I'm installing these base packages into the site-packages directories of Python distributions that I've installed, I'm isolated from the OS X's Python distributions.
  2. Using this method, should I be concerned about Glyph's comment that other things could potentially break (see his comment below)?

Again, I'm only interested in where to install those five base packages.

Related Questions/Info

I'm asking because of Glyph's comment to my answer to SO question 4314376, which stated:

NO. NEVER EVER do sudo python setup.py install whatever. Write a ~/.pydistutils.cfg that puts your pip installation into ~/.local or something. Especially files named ez_setup.py tend to suck down newer versions of things like setuptools and easy_install, which can potentially break other things on your operating system.

Previously, I asked What's the proper way to install pip, virtualenv, and distribute for Python?. However, no one answered the "why" of using ~/.local.

like image 606
Matthew Rankin Avatar asked Dec 29 '10 21:12

Matthew Rankin


2 Answers

There's no particularly good reason for or against installing in .local for Mac OS X installations using framework builds. There is still some controversy among Python core developers on this point with Glyph arguing that the .local location, introduced in Python 2.6 for other Unixy systems, should be used for Mac OS X and simplifies third-party installation processes, while others argue that the previous traditional locations for Mac OS X framework builds is more natural. In the end, it is up to you. Particularly if you are using virtual environments, if it works, don't worry about it.

like image 97
Ned Deily Avatar answered Oct 12 '22 09:10

Ned Deily


As of 2020, I do not think it is a good idea to install Python packages into .local, but to use virtualenv to create a separate environment for each package.

My reason

While installations into .local do not interfere with the system wide Python, you still can have conflicts between several packages installed into .local.

P.S.: If you do you like virtualenv you could also use pipx.

like image 40
Jürgen Gmach Avatar answered Oct 12 '22 08:10

Jürgen Gmach