easy_install or pip as a limited user?

Tag: python , pip , easy-install Author: zbfoy Date: 2013-03-24

Standard python distutils provides a '--user' option which lets me install a package as a limited user, like this:

python setup.py install --user

Is there an equivalent for easy_install and pip?

Best Answer

For pip, see User Installs for details, but basically, it's just what you'd expect:

pip install --user Foo

It's a bit trickier for easy_install. As Ned Deily points out, if you can rely on distribute rather than setuptools, and 0.6.11 or later, you can just use --user the same as pip. But if you need to work with setuptools, or older distribute… see Custom Installation Locations for details (and note that it explains how to create and set up user site packages, not just how to install there, because it needs to be able to work with Python 2.5 and earlier, which didn't do this by default). But hopefully, you're only using easy_install for the handful of packages that aren't pip-able, so that isn't a big deal.

However, it's at least worth considering whether virtualenv is a better fit for whatever you're trying to accomplish than a user site directory. pip and virtualenv work together very nicely, as the docs explain.


--user is directly supported in recent Distribute versions (0.6.11+) of easy_install.
@NedDeily: Thanks; I didn't know that. Does distribute have its own easy_install docs, separate from the original/setuptools/PEAK ones?
Yes it does: pythonhosted.org/distribute/… BTW, as you may have heard, it was announced at the recent PyCon that the setuptools project and the Distribute project have agreed to merge back into one project and source tree using the best features of both so, going forward, some time in the near future there should only be one version of setuptools and easy_install to contend with.
@NedDeily: Yeah, and I also heard that packaging, aka distutils2, was going to replace distutils, obsoleting setuptools and distribute, and including a new-and-improved pip, in time for 3.2, so… I'm optimistic, but cautious.
Such a skeptic! (And packaging was intended for 3.3.) Nick Coughlin, who is now leading the design for Python packaging enhancements and co-ordinating among the various projects, gives an overview of the plans here: python-notes.boredomandlaziness.org/en/latest/pep_ideas/…

Other Answer1

From the easy_install docs


--install-dir=DIR, -d DIR Set the installation directory. It is up to you to ensure that this directory is on sys.path at runtime, and to use pkg_resources.require() to enable the installed package(s) that you need.

(New in 0.4a2) If this option is not directly specified on the command line or in a distutils configuration file, the distutils default installation location is used. Normally, this would be the site-packages directory, but if you are using distutils configuration files, setting things like prefix or install_lib, then those settings are taken into account when computing the default installation directory, as is the --prefix option.

--prefix=DIR (New in 0.6a10) Use the specified directory as a base for computing the default installation and script directories. On Windows, the resulting default directories will be prefix\Lib\site-packages and prefix\Scripts, while on other platforms the defaults will be prefix/lib/python2.X/site-packages (with the appropriate version substituted) for libraries and prefix/bin for scripts.

Note that the --prefix option only sets the default installation and script directories, and does not override the ones set on the command line or in a configuration file.

You can also specify them on using a ~/.pydistutils.cfg file


Before installing EasyInstall/setuptools, just create a ~/.pydistutils.cfg file with the following contents (or add this to the existing contents):

[install] install_lib = ~/Library/Python/$py_version_short/site-packages install_scripts = ~/bin This will tell the distutils and EasyInstall to always install packages in your personal site-packages directory, and scripts to ~/bin. (Note: do not replace $py_version_short with an actual Python version in the configuration file! The distutils will substitute the correct value at runtime, so that the above configuration file should work correctly no matter what Python version you use, now or in the future.)

Once you have done this, you can follow the normal installation instructions and use easy_install without any other special options or steps.

(Note, however, that ~/bin is not in the default PATH, so you may have to refer to scripts by their full location. You may want to modify your shell startup script (likely .bashrc or .profile) or your ~/.MacOSX/environment.plist to include ~/bin in your PATH.


That's fine but it has nothing to do with the Distutils --user option that the OP is asking about. Granted, --user is not particularly well-documented or known. See docs.python.org/2/install/… Bottom line: setuptools doesn't currently support it; the Distribute fork does.