Passing arguments in python setup.py install_requires list

為{幸葍}努か 提交于 2019-12-01 18:11:24

问题


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

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.

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


回答1:


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



回答2:


Just replace PIL with Pillow (in your install_requires). It's a fork of PIL with bugfixes, py3k support and proper hosting. You don't need to change your code.



来源:https://stackoverflow.com/questions/25161727/passing-arguments-in-python-setup-py-install-requires-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!