python - 是否可以在 setup.py 中表达特定于平台的依赖项,而无需构建我的 egg 的特定于平台的版本?

标签 python setuptools distutils

我们有一个不包含代码的占位符 egg,它的存在只是为了从我们的 PyPi 存储库中拉下依赖包的列表。

这些依赖包中的大多数与平台无关,但有些仅用于 Win32 平台。

是否有可能以某种方式使依赖平台成为条件,以便我的 install_requires 列表中的给定依赖项只会在 Win32 上安装时被拉下?

或者:是否可以指定一个可选依赖项列表,如果可用则安装,但如果不可用则不会导致 easy_install 失败?

最佳答案

对于 sdist、egg 和 wheel 发布自:https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#platform-specific-dependencies

Sometimes a project might require a dependency to run on a specific platform. This could to a package that back ports a module so that it can be used in older python versions. Or it could be a package that is required to run on a specific operating system. This will allow a project to work on multiple different platforms without installing dependencies that are not required for a platform that is installing the project.

setup(
    name="Project",
    ...
    install_requires=[
        'enum34 ; python_version<"3.4"',
        'pywin32 >= 1.0 ; platform_system=="Windows"'
    ]
)

关于python - 是否可以在 setup.py 中表达特定于平台的依赖项,而无需构建我的 egg 的特定于平台的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6469508/

相关文章:

python - 什么时候应该使用 "Natural Language"PyPI 分类器?

python - Django,python3,安装时我得到 : "Parent module ' setuptools' not loaded"

python - 将 setuptools 与安装后和 python 依赖项一起使用

python - Python 发行版的用例是什么?

python - 使用 C 扩展 Python 错误 : Segmentation Fault: 11 in Python [MacOS X]

python - 如何在 Pandas 分组数据框中的二维列表的行之间应用最大函数

python - 在 python 中绘制 shapefile

python - subprocess.run 像 Popen 一样在后台执行

python - 比较两个数据框中的值

python 包 - 是否包含测试套件