Hide
Stay up to dateembedded code automagically updates, each snippet and article has a feed Join Siafoo Now or Learn More

Require One Package OR Another Atom Feed 0

In Brief Ever wish you could give a choice between prerequisites in your setup.py file? Now you can.... more
# 's
 1from setuptools import setup, find_packages
2from pkg_resources import require, DistributionNotFound
3
4# Load the PreferedDist only unless the LessPreferedDist is already installed
5try:
6 require('LessPreferedDist')
7 required='LessPreferedDist'
8except DistributionNotFound:
9 required = 'PreferedDist'
10
11setup(
12 name='MyPackage',
13 packages=find_packages(),
14 #...
15 install_requires=[
16 required,
17 'SomeOtherPackage'
18 ]
19)

Ever wish you could give a choice between prerequisites in your setup.py file? Now you can.

This code checks to see if your less preferred distribution is already installed. If it is, it is set as the required distribution, and if not your more preferred package is set as the required distribution.

The result of this is that if either is installed, it will be set as the required distribution, and installation will proceed. If neither is, the more preferred distribution will be set as the required distribution and be installed.