【问题标题】:setup.py install_require with options带有选项的 setup.py install_require
【发布时间】:2015-08-04 09:21:26
【问题描述】:

我需要在 setup.py 中通过install_require 将rjsmin 添加到我的依赖项中。

rjsmin 提供了一种通过使用--without-c-extensions 开关来禁用 c 扩展的方法,如下所示

python setup.py install --without-c-extensions

我想知道,如何将此开关添加到install_require 字符串中。

【问题讨论】:

标签: python setup.py


【解决方案1】:

我通过子类化setuptools.command.install 类并覆盖其run() 方法解决了我使用global-options 安装依赖项的问题,如以下代码 -

from setuptools import setup
from setuptools.command.install import install
from subprocess import call


class CustomInstall(install):
    def run(self):
        install.run(self)
        call(['pip', 'install', 'pycurl', '--global-option=--with-nss'])

setup( ...
      cmdclass={
          'install': CustomInstall,
      },
)

在这里,我正在安装带有全局选项--with-nss 的pycurl

【讨论】:

    【解决方案2】:

    您需要提供--install-option 或--global-option 以及要求文本。

    您可以参考doc here

    【讨论】:

    • 谢谢,我不知道这个选项 - 但我不能依赖 pip >= 7.0 :-/
    • 是的,我自己使用的是 1.5.6 版:D
    • 这似乎不适用于 pip 19.0.3。它在 requirements.txt 中有效,但在 install_requires 中无效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 2019-04-07
    • 1970-01-01
    • 2013-07-06
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多