问题描述
我正在尝试将Python软件包安装到我最近可以访问的系统上。我试图利用Python相对较新的,以及新选项-user
。 (该选项为,但是它在Python 2.6+中存在;您可以通过运行 python setup.py install --help
。)
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
.)
当我尝试运行时
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
该错误非常令人困惑,因为如您所见,我没有提供-前缀
,-exec前缀
,- install-base
或-install-platbase
标志作为命令行选项。我浪费了很多时间试图找出问题所在。我在下面记录我的答案,以期使另一些可怜的人省下几个小时的。
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.
推荐答案
一次解决方法:
One time workaround:
pip install --user --install-option="--prefix=" <package_name>
或
python setup.py install --user --prefix=
请注意,没有 =
之后的文本(甚至不是空格)。
Note that there is no text (not even whitespace) after the =
.
不要不要忘记-user
标志。
使用以下内容创建〜/ .pydistutils.cfg
(或等同于您的OS /平台):
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 =
.
然后运行必要的 pip install --user
或 python setup.py install --user
命令。 不要忘记-user
标志。
Then run the necessary pip install --user
or python setup.py install --user
commands. Do not forget the --user
flag.
最后,删除或重命名文件。在系统范围内(例如,没有-user
的用户)以该用户身份使用此〜/ .pydistutils安装Python软件包时,将该文件保留为当前内容将导致问题。 .cfg
。
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
.
这似乎是OpenSUSE和RedHat的问题,导致在这些平台上的。
This appears to be an issue with both OpenSUSE and RedHat, which has lead to a bug in virtualenv on these platforms.
错误源于系统级(在我的情况下为 /usr/lib64/python2.6/distutils/distutils.cfg
)在哪里
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
基本上,这等效于始终以 install --prefix = / usr / local
的身份运行install命令。您必须使用上面的一种技术来覆盖此规范。
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.
这篇关于将--user和--prefix错误与setup.py install结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!