7

My setup.py looks something like this:

from distutils.core import setup

setup(
    [...]
    install_requires=['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'],
    [...]
)

Under Python 2.6 (or higher) the installation of the ssl module fails with:

ValueError: This extension should not be used with Python 2.6 or later (already built in), and has not been tested with Python 2.3.4 or earlier.

Is there a standard way to define dependencies only for specific python versions? Of course I could do it with if float(sys.version[:3]) < 2.6: but maybe there is a better way to do it.

Michael Seiwald
  • 237
  • 2
  • 7
  • i cannot find install_requires as an argument to distutils.core.setup it seems left over from setuptools. http://docs.python.org/2/distutils/apiref.html#distutils.core.setup – jrwren Apr 23 '13 at 20:40

1 Answers1

12

It's just a list, so somewhere above you have to conditionally build a list. Something like to following is commonly done.

import sys

if sys.version_info < (2 , 6):
    REQUIRES = ['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'],
else:
    REQUIRES = ['gevent', 'configobj', 'simplejson', 'mechanize'],

setup(
# [...]
    install_requires=REQUIRES,
# [...]
)
Keith
  • 42,110
  • 11
  • 57
  • 76
  • 1
    There is now a better way, described in [this answer](https://stackoverflow.com/a/32643122/3565696) – ederag Jan 07 '18 at 10:17