Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install_requires in setup.py depending on installed Python version [duplicate]

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.

like image 900
Michael Seiwald Avatar asked May 21 '11 08:05

Michael Seiwald


People also ask

How do I set python version in setup py?

setup(name="my_package_name", python_requires='>3.5. 2', [...] Save this answer.

Is setup py outdated?

py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).

What should setup py contain?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.


1 Answers

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,
# [...]
)
like image 136
Keith Avatar answered Sep 21 '22 21:09

Keith