'Match versions between packages in setup.py install_requires

I have a package with setup.py which will depend on two packages, tensorflow and tensorflow-probability.

Q: How do I make sure the versions of the above two packages will always match when I install my package? My package currently has the requirement of tensorflow>=2.6.2 and I will be adding tensorflow-probability==tensorflow_MAJOR_MINOR_version.

The tensorflow-probability website has the following clause: https://www.tensorflow.org/probability/install

Note: Since TensorFlow is not included as a dependency of the TensorFlow Probability package (in setup.py), you must explicitly install the TensorFlow package (tensorflow or tensorflow-gpu). This allows us to maintain one package instead of separate packages for CPU and GPU-enabled TensorFlow.

This means it's up to the installer to install the correct tensorflow package version, but what if this is a setup.py script instead of a human?

I am not finding the syntax to do this in PEP 440 – Version Identification and Dependency Specification.

Dependency Management in Setuptools: Platform specific dependencies shows that it's possible to have conditional dependencies based on operating system platform.

My best guess is to augment setup.py with logic to:

* Get the currently installed version of `tensorflow` on the local system,
   or get the latest version that will be installed from pypl.
* Isolate the MAJOR.MINOR component of the fetched version.
* Use that version in a string replace for
   install_requires=[
           'tensorflow>=2.6.2',
           f'tensorflow-probability=={tensorflow_version}.*'
   ]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source