13

I am managing several modules on an HPC, and want to install some requirements for a tool using pip.

I won't use virtualenv because they don't work well with our module system. I want to install module-local versions of packages and will set PYTHONPATH correctly when the module is loaded, and this has worked just fine when the packages I am installing are not also installed in the default python environment.

What I do not want to do is uninstall the default python's versions of packages while I am installing module-local versions.

For example, one package requires numpy==1.6, and the default version installed with the python I am using is 1.8.0. When I

pip install --install-option="--prefix=$RE_PYTHON" numpy==1.6

where RE_PYTHON points to the top of the module-local site-packages directory, numpy==1.6 installs fine, then pip goes ahead and starts uninstalling 1.8.0 from the tree of the python I am using (why it wants to uninstall a newer version is beyond me but I want to avoid this even when I am doing a local install of e.g. numpy==1.10.1).

How can I prevent pip from doing that? It is really annoying and I have not been able to find a solution that doesn't involve virtualenv.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
  • Check this out: http://stackoverflow.com/questions/2915471/install-a-python-package-into-a-different-directory-using-pip – Joe Nov 09 '15 at 16:53
  • Why don't you want to use a virtualenv? Sounds like exactly what that's for. – Daniel Roseman Nov 09 '15 at 16:54
  • I use that trick to install a "local" copy of the package inside my python scripts folder. Then you can "from . import my_local_version" in the script to bypass the computer's local packages. – Joe Nov 09 '15 at 16:55

1 Answers1

17

You have to explicitly tell pip to ignore the current installed package by specifying the -I option (or --ignore-installed). So you should use:

PYTHONUSERBASE=$RE_PYTHON pip install -I --user numpy==1.6

This is mentioned in this answer by Ian Bicking.

Community
  • 1
  • 1
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
  • 1
    FYI, I noticed that when using the system pip (v1.1, on an old Debian version) to "upgrade" itself (i.e. install the new version in /usr/local to avoid overwriting system files) it ignores `--ignore-installed` for some reason. It just insists on trying to uninstall the existing installation. (I tried `-t /usr/local` and `--install-option="--prefix=/usr/local"`.) – Alastair Irvine May 20 '18 at 16:20