在python setup.py install_requires列表中传递参数 [英] Passing arguments in python setup.py install_requires list

查看:218
本文介绍了在python setup.py install_requires列表中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用pip来安装PIL.安装时需要两个附加参数.因此,安装命令如下所示.

I have used pip to install PIL. It requires two additional arguments while installation. So the command for installation looks something like this.

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

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

I need to add the PIL package in setup.py file. Adding PIL in the install_requires list do install PIL but it doesn't work, as I need to install PIL with the additional arguments.

那么如何将PIL与其他参数一起添加到install_requires列表中?

So how can I add the PIL to the install_requires list with additional arguments ?

推荐答案

当前,无法在setup.py的install_requires中指定其他参数.但是,我通过子类化setuptools.command.install类并覆盖其run()方法解决了使用global-options安装依赖项的问题,例如以下代码-

Currently, there is no way to specify extra arguments in install_requires in setup.py. But, I solved my problem of installing dependencies with global-options by sub-classing setuptools.command.install class and overriding its run() method, like following code -

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,
      },
)

这篇关于在python setup.py install_requires列表中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆