如何指定 python pip 的安装顺序?

发布于 2024-10-24 22:11:52 字数 450 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

音盲 2024-10-31 22:11:52

你可以只使用:

cat requirements.txt | xargs pip install

You can just use:

cat requirements.txt | xargs pip install
断爱 2024-10-31 22:11:52

要允许在requirements.txt中使用所有类型的条目(例如来自git存储库的包),您需要使用以下命令集

cat requirements.txt | xargs -n 1 -L 1 pip install

-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

cat requirements.txt | xargs -n 1 -L 1 pip install

-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.

断爱 2024-10-31 22:11:52

这是一个愚蠢的技巧,但可能会起作用。编写一个 bash 脚本,逐行从需求文件中读取并在其上运行 pip 命令。

#!/bin/bash
for line in $(cat requirements.txt)
do
  pip install $line -E /path/to/virtualenv
done

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.

#!/bin/bash
for line in $(cat requirements.txt)
do
  pip install $line -E /path/to/virtualenv
done
厌倦 2024-10-31 22:11:52

遗憾的是,升级建议不起作用。如果您阅读 https://github.com/pypa/pip/issues/24< 中的其他详细信息/a> 你会明白为什么

pip 在尝试安装之前会首先构建所有包。因此,对于如下所示的需求文件,

numpy==1.7.1
scipy==0.13.2
statsmodels==0.5.0

statsmodels 的构建将失败,并显示以下语句:

ImportError: statsmodels requires numpy

为需求文件中的每个条目手动调用 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

numpy==1.7.1
scipy==0.13.2
statsmodels==0.5.0

The build of statsmodels will fail with the following statement

ImportError: statsmodels requires numpy

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.

云归处 2024-10-31 22:11:52

Pymongo 需要 setuptools>=0.6c9

你怎么知道?需要构建或安装吗?您没有说明您尝试安装的 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 - 安装顺序 部分

从 v6.1.0 开始,pip 在其依赖项之前安装依赖项,即
按“拓扑顺序”。这是目前唯一的承诺点
与订单相关的制造。

后来:

在 v6.1.0 之前,pip 没有对安装顺序做出任何承诺。

然而,如果 Pymongo 没有正确规范要求,它也无济于事。

Pymongo requires setuptools>=0.6c9

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 run setup.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 its setup.py (as opposed to requiring setuptools to run setup 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:

As of v6.1.0, pip installs dependencies before their dependents, i.e.
in "topological order". This is the only commitment pip currently
makes related to order.

And later:

Prior to v6.1.0, pip made no commitments about install order.

However, without proper specification of requirements by Pymongo it won't help either.

私藏温柔 2024-10-31 22:11:52

如果您的需求文件中有评论,您将需要使用:

grep -v "^#" requirements.txt | xargs pip install

If you have comments in your requirements file you'll want to use:

grep -v "^#" requirements.txt | xargs pip install
红ご颜醉 2024-10-31 22:11:52

继 @lukasrms 的解决方案之后 - 我必须这样做才能让 pip 一次安装我的要求:

cat requirements.txt | xargs -n 1 pip install

Following on from @lukasrms's solution - I had to do this to get pip to install my requirements one-at-a-time:

cat requirements.txt | xargs -n 1 pip install
辞取 2024-10-31 22:11:52

我最终在 virtualenv 中运行 pip 而不是使用“pip -E”,因为使用 -E pip 仍然可以看到服务器站点包,这显然会搞乱一些安装。

我在没有 virtualenvs 的服务器上也遇到了麻烦。即使我使用单独的 pip 命令安装 setuptools pymongo 也会拒绝安装。

我通过使用 easy_install 单独安装 setuptools 解决了这个问题,因为这似乎是 pip 和 setuptools 之间的问题。

fabfile.py 的片段:

env.activate = "source %s/bin/activate" % virtualenv_path

_virtualenv("easy_install -U setuptools")
_virtualenv("pip install -r requirements.txt")

def _virtualenv(command)
    if env.virtualenv:
        sudo(env.activate + "&&" + command)
    else:
        sudo(command)

我在使用 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:

env.activate = "source %s/bin/activate" % virtualenv_path

_virtualenv("easy_install -U setuptools")
_virtualenv("pip install -r requirements.txt")

def _virtualenv(command)
    if env.virtualenv:
        sudo(env.activate + "&&" + command)
    else:
        sudo(command)

I had these problems with pip 0.8.3 and 0.8.2.

凉宸 2024-10-31 22:11:52

抱歉,我的第一个答案是错误的,因为我有 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

仅此而已 2024-10-31 22:11:52

这对我来说效果很好:

for name in "^numpy" "^scipy" "^cython" "^scikit"
do
    grep -r -h $name $requirements_dir | awk '{print($1)}' | xargs pip install
done

使用该解决方案,您无需修改​​原始需求文件,而是尝试提前以正确的顺序安装软件包。

Here is what worked nicely for me:

for name in "^numpy" "^scipy" "^cython" "^scikit"
do
    grep -r -h $name $requirements_dir | awk '{print($1)}' | xargs pip install
done

With that solution you don't modify the original requirement files, but you attempt to install packages in a correct order in advance.

如歌彻婉言 2024-10-31 22:11:52

以防万一你想删除所有注释,即使它们不是从新行开始

sed 's/#.*//' requirements.txt | grep -v '^

它会首先通过 sed 命令删除注释,然后使用 grep 删除空行>,然后从requirements.txt 文件中取出每一行并对其应用pip install 命令。它的工作原理就像两个单独的命令

| xargs -n 1 -L 1 pip install

它会首先通过 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

sed 's/#.*//' requirements.txt | grep -v '^

It will firstly remove comments by sed command, then removes empty lines with grep, and then take each line from the requirements.txt file and apply pip install command to it. It works like two separate commands

| xargs -n 1 -L 1 pip install

It will firstly remove comments by sed command, then removes empty lines with grep, and then take each line from the requirements.txt file and apply pip install command to it. It works like two separate commands

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文