【问题标题】:Pip:如何覆盖 requirements.txt 中的子依赖版本?
【发布时间】:2022-01-23 16:18:00
【问题描述】:

我最近切换到 Apple Silicon,现在正尝试将所有软件包安装到 requirements.txt 中的 Python 项目中。但是,由于架构不同,我无法满足所有要求,尤其是子依赖项。

requirements.txt

ethnicolr==0.8.1
# and many more, but this one is causing issues

使用pip install -r requirements.txt 安装它会产生

错误:找不到满足要求的版本 tensorflow==2.5.2(来自族裔)(来自版本:无)

TensorFlow 2.4.0 可用于此设置,并且它应该可以与ethnicolr 一起使用。那么如何覆盖requirements.txt中子依赖的版本呢?

顺便说一句,我正在将 Mambaforge 用于虚拟环境。因为在 Apple M1 上运行 PyData Stack 是 recommended

【问题讨论】:

    标签: python tensorflow pip conda apple-m1


    【解决方案1】:

    一种解决方法是显式设置依赖项并使用--no-deps 参数运行pip install

    将我的requirements.txt 设置为:

    ethnicolr==0.8.1
    # and many more, but this one is causing issues
    tensorflow==2.5.0 # You set this to whatever version you want to
    

    我跑了:

    > pip install --no-deps -r requirements.txt                                                                                      
    Collecting ethnicolr==0.8.1
      Using cached ethnicolr-0.8.1-py2.py3-none-any.whl (36.1 MB)
    Collecting tensorflow==2.5.0
      Using cached tensorflow-2.5.0-cp39-cp39-manylinux2010_x86_64.whl (454.4 MB)
    Installing collected packages: tensorflow, ethnicolr
    Successfully installed ethnicolr-0.8.1 tensorflow-2.5.0
    

    这意味着一个明确的问题:您必须事先知道您的软件包使用了哪些部门。要轻松找出这些,您可以使用pip-tools

    【讨论】:

    • 谢谢。问题是 TensorFlow 2.5.2 不适用于 M1 芯片。 Tensorflow 2.5.0 是,但它导致了种族问题。我认为没有简单的解决方法,我在ethnicolr repo 中提出了一个问题。
    • 你可以试试 2.6.0
    【解决方案2】:

    您应该安装一个对 tensorflow 版本没有特定要求的ethnicolr 版本。 pip install ethnicolr==0.2.0可以工作。

    【讨论】:

    • 谢谢。但是我的最低要求是ethnicolr == 0.4.0。还有其他方法可以覆盖版本吗?当前版本的种族自述文件说 tensorflow 2.x 有效
    • Ethnicolr 非常具体:github.com/appeler/ethnicolr/blob/master/requirements.txt 表示 2.5.2。
    • 对不起@Ola,似乎没有什么好的办法。在不知道 Ethnicolr 的具体实现方式的情况下,人们不得不假设 2.5.2 的要求是有充分理由的。如果您可以容忍您的应用程序有时会以不可预知的方式中断,您应该只使用--no-deps 开关。
    • 谢谢,我找到了一种在我的 M1 机器上安装 Tensorflow 2.5.0 的方法,它正在运行。但是有些功能失败了。我在ethnicolr repo 中提出了一个问题。这是在 m1 上安装 Tensorflow 2.5.0 的指南:medium.com/@theDrewDag/…
    猜你喜欢
    • 2014-07-21
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多