jayemar
jayemar

Reputation: 351

Different custom install locations for pip2 and pip3

When using pip with the --user flag, the default installation location is ~/.local/lib/pythonX.Y/site-packages, where X.Y specifiy the version of python. This allows for separation of packages installed using pip2 from those installed via pip3.

However, when using a pip.conf file to specify a target installation directory, I've only seen a global setting such as this:

[global]
target=/data/user/pip

This works, but doesn't separate packages installed by pip2 from those installed via pip3 which can cause issues. Is there a way to specify different locations for packages installed via pip2 and those installed via pip3?

Upvotes: 2

Views: 724

Answers (1)

hoefling
hoefling

Reputation: 66451

Unfortunately, there's no possibility to handle version-specific stuff in the pip config. The current decision about this is:

...it doesn't appear to be something we actually need.

However, the user installation target is actually configured not via --target, but via the PYTHONUSERBASE environment variable. This means that you can pass the user base from env, for example PYTHONUSERBASE=/some/dir pip install --user pkgname. If you want to persist the custom user base dir, I'd go with an alias. Example for bash: in your .bashrc/.bash_profile, add:

alias pip2='PYTHONUSERBASE=/tmp/pip2 pip2'
alias pip3='PYTHONUSERBASE=/tmp/pip3 pip3'
alias pip3.7='PYTHONUSERBASE=/tmp/pip3.7 pip3.7'
# etc

Save the file, reload with

source ~/.bashrc

or

source ~/.bash_profile

or simply open a new terminal. Now

$ pip2 install --user pkgname

will install to /tmp/pip2 etc.

Upvotes: 1

Related Questions