【问题标题】:Passing arguments in python setup.py install_requires list在 python setup.py install_requires 列表中传递参数
【发布时间】:2014-08-06 13:30:44
【问题描述】:

我使用 pip 来安装 PIL。它在安装时需要两个额外的参数。所以安装命令看起来像这样。

pip install PIL --allow-external PIL --allow-unverified PIL

我需要在 setup.py 文件中添加 PIL 包。在install_requires 列表中添加 PIL 确实会安装 PIL,但它不起作用,因为我需要使用附加参数安装 PIL。

那么如何将 PIL 添加到带有附加参数的 install_requires 列表中?

【问题讨论】:

  • 无法从 setup.py 传递额外的参数。问题是 PIL 不在 PyPi 上托管包。顺便说一句,看看 Pillow,它是 PIL 的一个分支,托管在 PyPi 上。

标签: python python-imaging-library pyramid setup.py


【解决方案1】:

目前,无法在 setup.py 中的 install_requires 中指定额外的参数。但是,我通过子类化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', 'PIL', '--allow-external', 'PIL', '--allow-unverified', 'PIL'])

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

【讨论】:

    【解决方案2】:

    只需将 PIL 替换为 Pillow(在您的 install_requires 中)。它是 PIL 的一个分支,带有错误修复、py3k 支持和适当的托管。您无需更改代码。

    【讨论】:

      猜你喜欢
      • 2016-10-08
      • 1970-01-01
      • 2013-01-02
      • 2018-11-03
      • 2012-04-06
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      相关资源
      最近更新 更多