I was trying to install Python packages a system I recently gained access to. I was trying to take advantage of Python's relatively new per user site-packages directory, and the new option --user
. (The option is currently undocumented, however it exists for Python 2.6+; you can see the help by running python setup.py install --help
.)
When I tried running
python setup.py install --user
on any package I downloaded, I always got the following error:
error: can't combine user with with prefix/exec_prefix/home or install_(plat)base
The error was extremely perplexing because, as you can see, I wasn't providing the --prefix
, --exec-prefix
, --install-base
, or --install-platbase
flags as command line options. I wasted a lot of time trying to figure out what the problem was. I document my answer below, in hopes to spare some other poor soul a few hours of yak shaving.
@joeforker, pip uses setup.py behind the scenes. If I want people to be able to install my package with pip, I need to create a setup.py file.
py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).
Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.
Building Wheels Building wheels from a setuptools based project is simple: python setup.py bdist_wheel. This will build any C extensions in the project and then package those and the pure Python code into a . whl file in the dist directory.
pip install --user --install-option="--prefix=" <package_name>
or
python setup.py install --user --prefix=
Note that there is no text (not even whitespace) after the =
.
Do not forget the --user
flag.
Create ~/.pydistutils.cfg
(or equivalent for your OS/platform) with the following contents:
[install] prefix=
Note that there is no text (not even whitespace) after the =
.
Then run the necessary pip install --user
or python setup.py install --user
commands. Do not forget the --user
flag.
Finally, remove or rename this file. Leaving this file present will cause issues when installing Python packages system-wide (i.e., without --user
) as this user with this ~/.pydistutils.cfg
.
This appears to be an issue with both OpenSUSE and RedHat, which has lead to a bug in virtualenv on these platforms.
The error stems from a system-level distutils configuration file (in my case /usr/lib64/python2.6/distutils/distutils.cfg
) where there was this
[install] prefix=/usr/local
Basically, this is equivalent to always running the install command as install --prefix=/usr/local
. You have to override this specification using one of the techniques above.
Posting to save others time, as no available answers worked for me...
In some environments, using the --target
(-t
) switch will still hit the same error. In my testing on two flavors of linux, I encountered the same issue when using the --prefix=
parameter.
Code:
PYTHONUSERBASE=/tmp/ pip install --user --force-reinstall $PACKAGE
Explanation: My workaround, which seems to work across many environments (MacOS, Amazon Linux, Debian) is to set the PYTHONUSERBASE
environment variable to a temp location. --force-reinstall
is used to trigger the local installation even when the package is already installed.
This will result in the module being compiled/installed (depending on the OS and Python version) to: /tmp/lib/python2.7/site-packages/*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With