2017-04-10 36 views
1

我在一个docker镜像上,所以我无法访问docker镜像的“外部”。我想安装tensorflow与所支持的CPU支持:用pip为gpu安装后找不到tensorflow

pip install tensorflow-gpu 

cudnn和CUDA已安装并正在运行。旧版本(0.11)在图像中可用,并且正在使用CUDA和cudnn运行,但我需要升级到版本1或更高版本。我有两个Nvidia Titans。

使用显示PIP命令我使用下面的脚本,看看我是否启用了GPU的支持,同时也看看NVIDIA-SMI后:

import tensorflow as tf 


# Creates a graph. 
with tf.device('/gpu:0'): 
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') 
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') 
    c = tf.matmul(a, b) 
# Creates a session with log_device_placement set to True. 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 
# Runs the op. 
print sess.run(c) 

在此之后我只得到输出

No module named tensorflow

如果我检查与PIP列表:

pip list | grep tensorflow 

我得到的输出:

tensorflow-gpu (1.0.1)

这是一个简单的错误导入吗?

如果我使用非GPU支持安装pip install tensorflow上面的代码给出:

Device mapping: no known devices.

这当然是由于不支持GPU的。所以总结一下,我如何获得tensorflow的GPU版本以使用简单的pip安装和1.0以上的版本?

+0

我会用'pip install tensorflow-gpu -log'来检查pip的完整安装日志。 – fedterzi

+0

您绝对需要GPU版本。 “no module”错误似乎表明您可能使用了错误版本的python。你确定你用来安装tensorflow的pip使用的是你运行代码的python吗? –

回答

2

安装它

conda install tensorflow-gpu 

解决了所有的问题。

+1

谢谢,我应该在尝试解决问题之前花费2天徒然尝试过 –

0

激活tensorflow有:

>>>source activate tensorflow 
+0

谢谢,这看起来像是对原始问题的解决方案,但是如果我运行此脚本,则会收到错误消息:文件“/opt/conda/lib/python2.7/site-packages/conda/install.py,第130行,在symlink_fn(root_file,prefix_file)(追踪最后一个错误)。这是一个新的错误,应该在一个新的问题? – Kev1n91

+2

我现在用conda安装tensorflow-gpu安装它,一切都像我想要的一样。 – Kev1n91