7

I'd want to install python modules as non-root user like this

$ pip install -I --install-option="--prefix=~/usr" scipy

Unfortunately this usually does not work unless you specify --user. But --user can't be used together with --prefix. Using --user only (without --prefix) installs to ~/.local which I find ugly because I have a well maintained ~/usr and don't want to add even more stuff to my env to make ~/.local usable too.

So my questions:

  1. How can I let --prefix and --user work together for setup.py or how else could setup.py succeed without using --user?
  2. Or can I change the user site directory from ~/.local to ~/usr somehow by env?
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
rudimeier
  • 854
  • 1
  • 8
  • 20
  • I don't see why `--install-option="--prefix=~/usr"` shouldn't work. Please tell us what error you get. – Piotr Dobrogost Jun 26 '14 at 08:24
  • For me --prefix works only if it's not installed globally already. It tries to uninstall the global module and aborts with error. Can I disable "uninstall" somehow? --ignore-installed is not enough. – rudimeier Jun 26 '14 at 11:14
  • I guess `--ignore-installed` is not compatible with `--install-option="--prefix=..."` as the former is pip's option while the latter is being passed directly to setuptools. You could try to use pip's `--target` option which should prevent pip from trying to uninstall system wide package. – Piotr Dobrogost Jun 26 '14 at 13:51
  • --target does not work neither. I had also tried a lot directly with setup.py to avoid any odd behavior of pip. (Note that there are some related bugs in pip <1.5.) Anyway, PYTHONUSERBASE is a good workaround, although --prefix should IMO simply do the same what we already know from "./configure --prefix ... && make install". – rudimeier Jun 26 '14 at 14:30

1 Answers1

8

To answer your first question:

In Installing Python Modules guide written by Greg Ward we read:

Note that the various alternate installation schemes are mutually exclusive: you can pass --user, or --home, or --prefix and --exec-prefix, or --install-base and --install-platbase, but you can’t mix from these groups.

To answer your second question:

In the same guide there's section Alternate installation: the user scheme where we read:

Files will be installed into subdirectories of site.USER_BASE

with site.USER_BASE linked to https://docs.python.org/2/library/site.html#site.USER_BASE. There we are asked to see also information on PYTHONUSERBASE environment variable:

Defines the user base directory, which is used to compute the path of the user site-packages directory and Distutils installation paths for python setup.py install --user.

Also, you might be interested in the home scheme:

The idea behind the “home scheme” is that you build and maintain a personal stash of Python modules. This scheme’s name is derived from the idea of a “home” directory on Unix, since it’s not unusual for a Unix user to make their home directory have a layout similar to /usr/ or /usr/local/.

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • 1
    Thanks! PYTHONUSERBASE env solves my issue. Unfortunately it was not mentioned in the man page. – rudimeier Jun 26 '14 at 11:20
  • @rudimeier: Right, man python mentions PYTHONNOUSERBASE but not PYTHONUSERBASE. Would you mind reporting this on bugs.python.org? – merwok Jun 26 '14 at 12:37
  • Do you really have PYTHONNOUSERBASE in man page? I have only PYTHONNOUSERSITE (option -s). Is *USERBASE another different thing than *USERSITE? I'm going to bug report it. – rudimeier Jun 26 '14 at 12:54
  • I mistyped, it’s indeed PYTHONNOUSERSITE. (The USERBASE envvar/option/variable is the base used to define USERSITE and other directories like the scripts dir.) – merwok Jun 29 '14 at 20:22
  • wtf are there env variables we can set or..? As only an occassional user of python, I don't know what `site.USER_BASE` refers to. – Alexander Mills May 22 '19 at 21:05