将 --user 与 --prefix 错误与 setup.py install 结合使用 [英] Combine --user with --prefix error with setup.py install

查看:36
本文介绍了将 --user 与 --prefix 错误与 setup.py install 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我最近获得访问权限的系统上安装 Python 包.我试图利用 Python 相对较新的 每个用户的站点包目录,以及新选项--user.(该选项是当前未记录,但它存在于 Python 2.6+ 中;您可以通过运行 <代码>python setup.py install --help.)

当我尝试跑步时

python setup.py install --user

在我下载的任何包上,我总是收到以下错误:

error: can't combine user with prefix/exec_prefix/home or install_(plat)base

这个错误非常令人困惑,因为正如你所看到的,我没有提供 --prefix--exec-prefix--install-base--install-platbase 标志作为命令行选项.我浪费了很多时间试图找出问题所在.我在下面记录了我的答案,希望能让其他一些可怜的人花几个小时的牦牛剃须.

解决方案

一次性解决方法:

pip install --user --install-option="--prefix=" 

python setup.py install --user --prefix=

请注意,= 之后没有文本(甚至没有空格).

不要忘记 --user 标志.

安装多个包:

使用以下内容创建 ~/.pydistutils.cfg(或等效于您的操作系统/平台):

[安装]前缀=

请注意,= 之后没有文本(甚至没有空格).

然后运行必要的 pip install --userpython setup.py install --user 命令.不要忘记 --user 标志.

最后,删除或重命名此文件.保留此文件将导致在系统范围内安装 Python 包时出现问题(即,没有 --user)作为此用户使用此 ~/.pydistutils.cfg.>

这个问题的原因

这似乎是 OpenSUSE 和 RedHat 的问题,导致了virtualenv 中的错误在这些平台上.

该错误源于系统级 distutils 配置文件(在我的情况下/usr/lib64/python2.6/distutils/distutils.cfg) 哪里有这个

[安装]前缀=/usr/local

基本上,这相当于始终以 install --prefix=/usr/local 的形式运行安装命令.您必须使用上述技术之一覆盖此规范.

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.

解决方案

One time workaround:

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.

Installing multiple packages:

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.

The cause of this issue

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.

这篇关于将 --user 与 --prefix 错误与 setup.py install 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆