0

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']

4

1 回答 1

2

你可以这样写:

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' ]
       ....
      ) 
于 2013-01-10T06:49:45.833 回答