简体   繁体   English

python setup.py:安装tensorflow还是tensorflow-gpu?

[英]python setup.py: install either tensorflow or tensorflow-gpu?

I'm designing a new project which requires tensorflow . 我正在设计一个需要张量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? 由于TensorFlow具有多个安装( tensorflowtensorflow-gpu ),我如何在install_requires部分中添加两个都可以呢?

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM