When using setuptools install script ( setup.py), you check the required module and update the list of installation dependencies to add backports if necessary.
For example, let's say you need a class collections.OrderedDict. The documentation states that it was added in Python 2.7, but the backport is available nofollow noreferrer is available →, which works on Python 2.4 and higher. In setup.pyyou check for class c collections. If import is not possible, add back to the list of requirements:
from setuptools import setup
install_requires = []
try:
from collections import OrderedDict
except ImportError:
install_requires.append('ordereddict')
setup(
install_requires=install_requires
)
then in your code where you need OrderedDictuse the same test:
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
and rely on pipeither easy_installor zc.buildoutor other installation tools to get an extra library for you.
backports, json ( simplejson), argparse, sqlite3 ( pysqlite, from pysqlite2 import dbapi as sqlite3 ).
; Python , , , , , Python .