7

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?

Ned Deily
  • 78,314
  • 15
  • 120
  • 148
Giampaolo Rodolà
  • 10,883
  • 5
  • 58
  • 57
  • considre virtual env. it could be maintained per user – karthikr Apr 09 '13 at 21:29
  • fyi, `pip` likes to reinstall dependencies , while `easy_install` will leave already-met dependencies alone. – Jonathan Vanasco Apr 09 '13 at 21:41
  • @JonathanVanasco: If you're trying to sidetrack this question into an argument about `pip` vs. `easy_install`, that's not at all relevant to this question; go to [Why use pip over easy_install](http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install). – abarnert Apr 09 '13 at 22:06
  • 2
    I really hate the idea of defending myself but WTF!? If I wanted to sidetrack this question, I would have easily done so. I'm perfectly capable of sidetracking questions - it's not very hard to do. Does my comment honestly look like an attempt at sidetracking or flame-baiting to you, or do you just like to overmoderate? The user asked how to accomplish something using two options; I noted a little-known feature of one that might be applicable their decision. I offered no pros, cons, recommendations, or preference. That's no more off-point than talking about the applicability of `virtualenv`. – Jonathan Vanasco Apr 09 '13 at 22:37

3 Answers3

7

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.

abarnert
  • 313,628
  • 35
  • 508
  • 596
  • 2
    `--user` is directly supported in recent Distribute versions (0.6.11+) of `easy_install`. – Ned Deily Apr 09 '13 at 21:46
  • @NedDeily: Thanks; I didn't know that. Does distribute have its own `easy_install` docs, separate from the original/setuptools/PEAK ones? – abarnert Apr 09 '13 at 22:03
  • Yes it does: http://pythonhosted.org/distribute/easy_install.html#using-easy-install 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. – Ned Deily Apr 10 '13 at 04:31
  • @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. – abarnert Apr 10 '13 at 07:52
  • 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: http://python-notes.boredomandlaziness.org/en/latest/pep_ideas/core_packaging_api.html – Ned Deily Apr 10 '13 at 13:31
  • @NedDeily: I did say "optimistic, but cautious", not just "cautious". When `distutils2` was pushed back from 2.7/3.2 to 3.3 (see [this thread](http://mail.python.org/pipermail/python-dev/2012-June/120430.html) for a summary of the history), everyone believed it would be easily doable in time, and everyone turned out to be wrong. That doesn't mean it will definitely, or even likely, happen again, it's just a reminder that it's not impossible that it'll happen again. – abarnert Apr 10 '13 at 19:31
0

From the easy_install docs

http://peak.telecommunity.com/DevCenter/EasyInstall#downloading-and-installing-a-package

--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

http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-installation

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.

Jonathan Vanasco
  • 13,535
  • 8
  • 42
  • 67
  • 1
    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 http://docs.python.org/2/install/index.html#alternate-installation-the-user-scheme Bottom line: `setuptools` doesn't currently support it; the Distribute fork does. – Ned Deily Apr 10 '13 at 04:38
0

I needed to do the same with my docker and deploy to AWS Elastic Beanstalk.

The issue is that pip and easy_install (called by python setup.py) interpret the --user parameter in different way.

  • pip install --user PackageName will install the PackageName to $PYTHONUSERBASE environment variable.
  • python setup.py develop --user will ignore $PYTHONUSERBASE variable and always install to ~/.local/lib/python<python version>/site-packages folder

The only way I found for both these folders works together, is to delete ~/.local/lib/python<python version>/site-packages and to make link to your $PYTHONUSERBASE

PS: Be careful with bellow, you may need to reinstall all your local python dependencies. I recommend use it only in docker or any other virtual environment

# !!! Be sure you have configured $PYTHONUSERBASE environment variable
rm -r ~/.local/lib/python2.7/site-packages
ln -s $PYTHONUSERBASE/lib/python2.7/site-packages ~/.local/lib/python2.7/site-packages

Now both pip and python setup.py devel --user will install to the same folder

Kostanos
  • 7,911
  • 3
  • 39
  • 59