Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make an "either... or... " distinction for install_requires in setup.py

If designing a setup.py and there are requirements that can be fulfilled through two different modules, i.e. only one of the two needs to be installed, how do I express that in the install_requires line? E.g. the setup.py looks like this:

setup(
    name='my_module',
    version='0.1.2',
    url='...',

    ...,

    install_requires=['numpy', 'tensorflow']
)

When doing pip install my_module this will install tensorflow (CPU) as a requirement, even though tensorflow-gpu is installed (which would meet the requirement as well, but doesn't, since it's named differently).

Can I do something like:

    install_requires=['numpy', 'tensorflow' or 'tensorflow-gpu']
like image 346
Honeybear Avatar asked Oct 14 '25 14:10

Honeybear


1 Answers

You need an extras_require in your setup function:

extras_require = {
    'gpu':  ['tensorflow-gpu'],
    'cpu': ['tensorflow']
},

Which then can be installed with:

pip install your_package[gpu] or pip install your_package[cpu]

Source

like image 99
Carlo Mazzaferro Avatar answered Oct 17 '25 02:10

Carlo Mazzaferro