python - python setup.py:安装 tensorflow 还是 tensorflow-gpu?
问题描述
我正在设计一个需要tensorflow
. 由于 TensorFlow 有多个安装(tensorflow
和tensorflow-gpu
),我如何在我的install_requires
部分中添加任何一个都可以?
解决方案
所以我是这样解决的:
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)
推荐阅读
- c# - 登录应用程序主屏幕后,需要在 15 分钟内提醒用户即将到来的约会(如果已安排)
- python - 按计数从熊猫数据框中提取最常见的 2 列组合
- angular - MatTableDataSource 无法读取 Angular 7 中未定义的属性“数据”
- angularjs - 仅显示日历特定日期的标题
- nginx - 在 nginx 中使用 lua 脚本发布请求处理
- azure - Azure LetsEncrypt 无法访问我的函数的 .well-known/acme-challenge
- karate - 当字符串值中包含“-”时,该值在 JSON 对象中被截断
- c# - DelegatingHandler 中的私有变量混合来自其他请求的值
- c# - 为什么在我传递(按值)字典时会生成 $ReturnValue1
> 到一个函数 - spring-boot - spring boot如何找到META-INF/spring.factories的路径