如何指定 python pip 的安装顺序?
我正在使用 Fabric(0.9.4)+pip(0.8.2),我需要为多个服务器安装一些 python 模块。所有服务器都有旧版本的 setuptools (0.6c8),需要升级 pymongo 模块。 Pymongo 需要 setuptools>=0.6c9。
我的问题是 pip 使用 pymongo 而不是 setuptools 开始安装,这会导致 pip 停止。在需求文件中打乱模块顺序似乎没有帮助。
requirements.txt:
setuptools>=0.6c9
pymongo==1.9
simplejson==2.1.3
有没有办法指定 pip 的安装顺序,因为它本身似乎无法正确执行?
这可以通过两个单独的需求文件来解决,但如果我现在或将来不需要维护多个需求文件,那就太好了。
pip 0.8.3 问题仍然存在。
I'm working with fabric(0.9.4)+pip(0.8.2) and I need to install some python modules for multiple servers. All servers have old version of setuptools (0.6c8) which needs to be upgraded for pymongo module. Pymongo requires setuptools>=0.6c9.
My problem is that pip starts installation with pymongo instead of setuptools which causes pip to stop. Shuffling module order in requirements file doesn't seem to help.
requirements.txt:
setuptools>=0.6c9
pymongo==1.9
simplejson==2.1.3
Is there a way to specify install order for pip as it doesn't seem to do it properly by itself?
This can be resolved with two separate requirements files but it would be nice if I didn't need to maintain multiple requirements files now or in the future.
Problem persists with pip 0.8.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
你可以只使用:
You can just use:
要允许在requirements.txt中使用所有类型的条目(例如来自git存储库的包),您需要使用以下命令集
-n 1和-L 1选项是需要逐一安装软件包并将requirements.txt 文件中的每一行视为单独的项目。
To allow all types of entries (for example packages from git repositories) in requirements.txt you need to use the following set of commands
-n 1 and -L 1 options are necessary to install packages one by one and treat every line in the requirements.txt file as a separate item.
这是一个愚蠢的技巧,但可能会起作用。编写一个 bash 脚本,逐行从需求文件中读取并在其上运行 pip 命令。
This is a silly hack, but might just work. Write a bash script that reads from your requirements file line by line and runs the pip command on it.
遗憾的是,升级建议不起作用。如果您阅读 https://github.com/pypa/pip/issues/24< 中的其他详细信息/a> 你会明白为什么
pip 在尝试安装之前会首先构建所有包。因此,对于如下所示的需求文件,
statsmodels 的构建将失败,并显示以下语句:
为需求文件中的每个条目手动调用 pip(通过 shell 脚本)给出的解决方法似乎是当前唯一的解决方案。
Sadly the upgrade suggestion won't work. If you read the other details in https://github.com/pypa/pip/issues/24 you will see why
pip will build all packages first, before attempting to install them. So with a requirements file like the following
The build of statsmodels will fail with the following statement
The workaround given for manually calling pip for each entry in the requirements file (via a shell script) seems to be the only current solution.
你怎么知道?需要构建或安装吗?您没有说明您尝试安装的 Pymongo 版本,但查看当前(3.2.2)版本的
setup.py
文件,没有说明 Pymongo 运行setup 所需的内容.py
(setup_requires
) 或安装所需的内容 (install_requires
)。如果没有此类信息,pip 无法确保 setuptools 的特定版本。如果 Pymongo 需要特定版本的 setuptools 来运行其 setup.py (而不是要求 setuptools 运行 setup 函数本身),那么另一个问题是,直到最近还没有方式来指定这一点。现在有规范 - PEP 518 - 指定最低构建系统要求Python 项目,应该很快就会在 pip 中实现 - 实现 PEP 518 支持 #3691。至于安装顺序,在 pip 6.1.0 中已修复;
来自pip install - 安装顺序 部分:
后来:
然而,如果 Pymongo 没有正确规范要求,它也无济于事。
How do you know? Requires to build or to install? You don't say what version of Pymongo you were trying to install but looking at
setup.py
file for current (3.2.2) version there's no specification of neither what Pymongo requires to runsetup.py
(setup_requires
) nor what it requires to install (install_requires
). With no such information pip can't ensure specific version of setuptools. If Pymongo requires specific version of setuptools to run itssetup.py
(as opposed to requiring setuptools to runsetup
function itself) then the other problem is that until recently there was no way to specify this. Now there's specification – PEP 518 – Specifying Minimum Build System Requirements for Python Projects, which should be shortly implemented in pip – Implement PEP 518 support #3691.As to order of installation, this was fixed in pip 6.1.0;
From pip install – Installation Order section of pip's documentation:
And later:
However, without proper specification of requirements by Pymongo it won't help either.
如果您的需求文件中有评论,您将需要使用:
If you have comments in your requirements file you'll want to use:
继 @lukasrms 的解决方案之后 - 我必须这样做才能让 pip 一次安装我的要求:
Following on from @lukasrms's solution - I had to do this to get pip to install my requirements one-at-a-time:
我最终在 virtualenv 中运行 pip 而不是使用“pip -E”,因为使用 -E pip 仍然可以看到服务器站点包,这显然会搞乱一些安装。
我在没有 virtualenvs 的服务器上也遇到了麻烦。即使我使用单独的 pip 命令安装 setuptools pymongo 也会拒绝安装。
我通过使用 easy_install 单独安装 setuptools 解决了这个问题,因为这似乎是 pip 和 setuptools 之间的问题。
fabfile.py 的片段:
我在使用 pip 0.8.3 和 0.8.2 时遇到了这些问题。
I ended up running pip inside virtualenv instead of using "pip -E" because with -E pip could still see servers site-packages and that obviously messed up some of the installs.
I also had trouble with servers without virtualenvs. Even if I installed setuptools with separate pip command pymongo would refuse to be installed.
I resolved this by installing setuptools separately with easy_install as this seems to be problem between pip and setuptools.
snippets from fabfile.py:
I had these problems with pip 0.8.3 and 0.8.2.
抱歉,我的第一个答案是错误的,因为我有 setuptools>=0.6c9。
看来不行,因为pymongo的setup.py需要setuptools>=0.6c9,但是pip只下载了setuptools>=0.6c9,还没有安装。
我之前提到的问题里有人讨论过这个问题。
几周前我自己创建了一个关于它的问题: 不要运行
egg_info
在安装之前的软件包之前添加到需求列表中的每个软件包。抱歉打扰了。
第一个答案:
将你的 pip 升级到 0.8.3 版本,它有一个安装顺序的错误修复 。
现在,如果您升级一切正常:-)
请在此处查看新闻:http:// /www.pip-installer.org/en/0.8.3/news.html
Sorry, my first answer was wrong, because I had setuptools>=0.6c9.
It seems it is not possible because pymongo's setup.py needs setuptools>=0.6c9, but pip has only downloaded setuptools>=0.6c9, and not installed yet.
Someone discussed about it in the issue I pointed before.
I have my own created an issue some weeks ago about it: Do not run
egg_info
to each package in requirements list before installing the previous packages.Sorry for the noisy.
First answer:
Upgrade your pip to 0.8.3 version, it has a bugfix to installation order.
Now if you upgrade everything works :-)
Check the news here: http://www.pip-installer.org/en/0.8.3/news.html
这对我来说效果很好:
使用该解决方案,您无需修改原始需求文件,而是尝试提前以正确的顺序安装软件包。
Here is what worked nicely for me:
With that solution you don't modify the original requirement files, but you attempt to install packages in a correct order in advance.
以防万一你想删除所有注释,即使它们不是从新行开始
它会首先通过 sed 命令删除注释,然后使用 grep 删除空行>,然后从requirements.txt 文件中取出每一行并对其应用pip install 命令。它的工作原理就像两个单独的命令
Just in case you want to erase all the comments, even if they don't begin from the new line
It will firstly remove comments by
sed
command, then removes empty lines withgrep
, and then take each line from the requirements.txt file and apply pip install command to it. It works like two separate commands