我正在设计一个需要tensorflow
的新项目。由于TensorFlow具有多个安装(tensorflow
和tensorflow-gpu
),我该如何在我的install_requires
部分中添加以下任意一项?
答案 0 :(得分:0)
这就是我的解决方法:
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)