【问题标题】:Setup.py skip dev dependency from requirements.txtSetup.py 从 requirements.txt 中跳过开发依赖项
【发布时间】:2021-09-08 09:10:18
【问题描述】:

我有一个包含以下依赖项的 requirements.txt 文件:

PyYAML
requests
nose
tox
mock
coverage

我希望 setup.py 跳过鼻子、毒物模拟和覆盖依赖项。我的 setup.py 文件如下所示:

#!/usr/bin/env python3
"""Setup Information."""
from setuptools import setup, find_packages

with open('requirements.txt') as f:
    required_dependencies = f.read().splitlines()

setup(
    name="DemoModule",
    version="1.0",
    description="A library with inputs",
    packages=find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: SomeLicences.com",
        "Operating System :: OS Independent",
    ],
    install_requires=required_dependencies,
)

【问题讨论】:

    标签: python python-3.x setuptools packaging setup.py


    【解决方案1】:

    简单的答案是在 setup.py 中添加一行,如下所示

    #!/usr/bin/env python3
    """Setup Information."""
    from setuptools import setup, find_packages
    
    with open('requirements.txt') as f:
        required_dependencies = f.read().splitlines()
    
    # Do not install nose
    required_dependencies.remove('nose')
    
    setup(
        name="DemoModule",
        version="1.0",
        description="A library with inputs",
        packages=find_packages(),
        classifiers=[
            "Programming Language :: Python :: 3",
            "License :: SomeLicences.com",
            "Operating System :: OS Independent",
        ],
        install_requires=required_dependencies,
    )
    

    但是,将其从 requirements.txt 中删除可能会更简洁并完成同样的事情。

    了解更多关于这个问题以及为什么安装鼻子会给您带来问题会很有帮助。

    【讨论】:

    • 原因是它更像是一个公共包,可以被所有其他包用作依赖项,但是 dev 依赖项(如nose、coverage、mock 等)会与它们拥有的其他依赖项产生版本冲突从其他包传入。
    • 你可能想看看 conda:docs.conda.io/en/latest
    猜你喜欢
    • 2014-07-21
    • 2015-01-10
    • 1970-01-01
    • 2021-08-05
    • 2016-10-24
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多