Provide a complex condition in install_requires ( Python setuptools's setup.py )

≡放荡痞女 提交于 2019-12-13 05:42:18

问题


Does anybody know how I can provide a complex condition in the "install_requires" section of setup.py?

Something like this:

install_requires = ['project1 >= 0.0.1 or project2 >=0.0.2', 'project3==0.9.0']


回答1:


You can write something like this:

def choose_proper_prject( requires ):
    import pkg_resources
    for req in requires:
       try:
           pkg_resources.require( req )
           return [ req ]
       except pkg_resources.DistributionNotFound :
           pass
       pass
    print “There are no proper project installation available”
    print “To use this app one of the following project versions have to be installed - %s” % requires
    import os; os._exit( os.EX_OK )
    pass


setup( ....
       install_requires = choose_proper_prject( [ 'project1 >= 0.0.1', 'project2>=0.0.2' ]) + [ 'project3==0.9.0' ]
       ....
      ) 


来源:https://stackoverflow.com/questions/14036181/provide-a-complex-condition-in-install-requires-python-setuptoolss-setup-py

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