【问题标题】:Install specific version of setuptools as a dependency of package安装特定版本的 setuptools 作为包的依赖项
【发布时间】:2021-01-01 08:44:33
【问题描述】:

我的包在依赖项中有 setuptools。我试图在安装我的包时限制 setuptools 的版本。 该软件包在 setup.py 中有以下限制:

setup(
    setup_requires=[
        'setuptools==50.2.0',
        'pip>=19,!=20.0,!=20.0.1,<21'
        ],
...

在pyproject.toml中也有同样的限制:

[build-system]
requires = ["setuptools==50.2.0", "pip>=19,!=20.0,!=20.0.1,<21", "wheel"]  # PEP 508 specifications.

但是,当使用 pip 安装我的包时,它会下载最新的 setuptools 50.3.0。

为什么它忽略了要求?如何让它不安装最新版本?

【问题讨论】:

  • 我相信没有用例将setuptoolspip 添加到setup_requires 是有意义的,同样,我无法想到将pip 添加到build-system.requires 的场景有意义的。另一方面,build-system.requires 中的 setuptools(也许是 wheel,但我有疑问)似乎是正确的做法。
  • 使用python的环境是这样的:xkcd.com/1987,你可以用多种方式做一件事,这取决于你的出发点是什么。将pip 添加到需求中可能没有多大意义,但我可以看到一些系统没有开箱即用的setuptools(尤其是旧的Python 版本)
  • 你能分享一下你的包的其余部分吗,具体来说你的install_requires是什么?
  • @AnthonySottile, install_requires=['cryptography&gt;=2.4.2,&lt;3', 'click&gt;=7.0,&lt;8', 'intelhex&gt;=2.2.1,&lt;3', 'python-jose&gt;=3.0.1,&lt;4', 'jsonschema&gt;=3.0.0,&lt;4', 'pyocd==0.27.3', 'cbor==1.0.0', 'imgtool==1.7.0a1'],
  • 好的。但这就是@rite2hhh 在他的回答中已经说过一段时间了:版本在范围内。现在修正了版本范围(固定到单个版本号),Anthony Sottile 提出了一点,即存在 build-timerun-time 依赖项.您的问题只是关于 build 依赖项(仅限制那些),与 install 无关。 -- 所以问题仍然是你关心“它下载最新的setuptools 50.3.0”?您是否关心 build-timerun-time

标签: python pip setuptools setup.py pyproject.toml


【解决方案1】:

感谢答案和cmets,我可以得出结论。

要使用特定版本的 setuptools,必须在两个位置都有它 - pyproject.tomlinstall_requires 的开头> setup.py.

pip 之类的工具将使用 pyproject.toml 中的版本来构建项目。但是,如果有任何依赖项在其要求中包含最新版本的 setuptools,则将使用最新版本来安装依赖项。此外,环境将保留上次安装的版本。

【讨论】:

    【解决方案2】:

    我认为您对构建时间(setup_requires / pyproject.toml build-system requires)和安装时间(install_requires)感到困惑。在安装时,您将获得未固定的 setuptools,因为它是一个没有版本限制的传递依赖

    setuptools 正在通过install_requires 中的传递依赖被拉入(特别是:jsonschema):

    $ visualize-requirements t.txt
     cryptography>=2.4.2,<3
       - cffi!=1.11.3,>=1.8
         - pycparser
       - six>=1.4.1
     click>=7.0,<8
     intelhex<3,>=2.2.1
     python-jose<4,>=3.0.1
       - pyasn1
       - rsa
         - pyasn1>=0.1.3
       - ecdsa<0.15
         - six
       - six<2.0
     jsonschema<4,>=3.0.0
       - six>=1.11.0
       - attrs>=17.4.0
       - setuptools
       - pyrsistent>=0.14.0
     pyocd==0.27.3
       - intervaltree<4.0,>=3.0.2
         - sortedcontainers<3.0,>=2.0
       - pylink-square
         - six
         - psutil>=5.2.2
         - future
       - cmsis-pack-manager>=0.2.7
         - milksnake>=0.1.2
           - cffi>=1.6.0
             - pycparser
         - appdirs>=1.4
         - pyyaml>=3.12
       - pyelftools
       - six<2.0,>=1.0
       - colorama
       - prettytable
       - pyusb>=1.0.0b2,<2.0
       - pyyaml<6.0,>=5.1
       - intelhex<3.0,>=2.0
     cbor==1.0.0
     imgtool==1.7.0a1
       - intelhex>=2.2.1
       - click
       - cryptography>=2.4.2
         - cffi!=1.11.3,>=1.8
           - pycparser
         - six>=1.4.1
       - cbor>=1.0.0
    

    我正在使用我编写的名为 requirements-tools 的工具中的 visualize-requirements

    【讨论】:

    • 你的意思是setuptools是和jsonschema一起安装的吗?我刚刚尝试从我的包 pyproject.toml 文件中删除 setuptools 并得到ModuleNotFoundError: No module named 'setuptools'
    • 我认为您对构建时间(setup_requires / pyproject.toml build-system requires)和安装时间(install_requires)感到困惑。在安装时,您将获得未固定的 setuptools,因为它是一个没有版本限制的传递依赖
    • 嗯,要求是按顺序处理的,所以顺序很重要,将setuptools 作为第一个“要求”将始终符合该要求。 @Elephant,我正在测试你的 setup.py 文件
    【解决方案3】:

    似乎准确,50.3.0 大于 40.0,小于 51,不等于 46.0 或 50.0。您可能需要进一步限制您的要求。如果您知道自己想要哪个版本,只需明确指定即可

    编辑:

    我创建了一个新的 venv 并检查了 pip list,似乎使用了足够高的 pip 版本,setuptools 是 50.3.0。

    $ pip3 -V
    pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
    $ pip3 list | grep setup
    setuptools (20.7.0)
    You are using pip version 8.1.1, however version 20.2.3 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    

    venv 内部(假设 Python 3.x)

    $ . vv/bin/activate
    (vv) $ pip3 -V
    pip 20.2.3 from /home/user/vv/lib/python3.5/site-packages/pip (python 3.5)
    (vv) $ pip3 list | grep setup
    DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
    setuptools 50.3.0
    

    【讨论】:

    • 限制为 v50.2.0,但仍安装 50.3.0 - requires = ["setuptools==50.2.0", "pip&gt;=19,!=20.0,!=20.0.1,&lt;21", "wheel"] # PEP 508 specifications.
    • 是预装的吗?确保您从干净的环境重新开始。如果它是使用pip 安装的,可以尝试--force-reinstall-I/--ignore-installed 忽略以前安装的相同包(pip3 install --help
    • 不,我之前清理过我的虚拟环境。
    • @Elephant,检查编辑,看看是否有帮助,你可能不得不强制降级(我不知道该怎么做)
    猜你喜欢
    • 2018-10-28
    • 1970-01-01
    • 2012-02-01
    • 2014-10-02
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 2013-04-09
    相关资源
    最近更新 更多