I'm designing a new project which requires tensorflow
. As TensorFlow has more than one installation ( tensorflow
and tensorflow-gpu
) how do I add to my install_requires
section that either one is fine?
So here's how I worked it out:
from pkg_resources import DistributionNotFound, get_distribution
from setuptools import setup, find_packages
def get_dist(pkgname):
try:
return get_distribution(pkgname)
except DistributionNotFound:
return None
install_deps = ['numpy', 'tensorflow']
if get_dist('tensorflow') is None and get_dist('tensorflow-gpu') is not None:
install_deps.remove('tensorflow')
setup(..., install_requires=install_deps)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.