简体   繁体   中英

Cannot find tensorflow after installing with pip for gpu

I am on a docker image, so I can not access the "outside" of the docker image. I want to install tensorflow with gpu support so used:

pip install tensorflow-gpu 

cudnn and CUDA is installed and working. An old version (0.11) is available in the image and is running with CUDA and cudnn just fine, but I need to upgrade to version 1 or higher. I have two Nvidia Titans.

After using the shown pip command I use the following script to see if I have GPU support enabled, and also look at 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)

After this I only get the output

No module named tensorflow

If I check the pip list with:

pip list | grep tensorflow

I get the output:

tensorflow-gpu (1.0.1)

Is it a simple wrong import?

If I use the non-gpu-support install pip install tensorflow the above code gives:

Device mapping: no known devices.

Which of course is due to no support of the gpu. So to summarize, how do I get the GPU Version of tensorflow to work with a simple pip install and a version above 1.0 ?

Installing it with

conda install tensorflow-gpu 

resolved all issues.

使用以下命令激活张量流:

>>>source activate tensorflow

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.

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