Tensorflow 1.5 ImportError: No module named tensorflow.python.client

+3 votes

Im trying to run a simple python script that uses Tensorflow to print the available GPU devices. The script is

from tensorflow.python.client import device_lib

def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']

get_available_gpus()

I have the following related modules installed:

pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.5/dist-packages
Requires: wheel, six, tensorflow-tensorboard, numpy, absl-py, protobuf

However, when I run the script I get the following error:

python get_available_gpus.py 
Traceback (most recent call last):
  File "get_available_gpus.py", line 2, in <module>
    from tensorflow.python.client import device_lib
ImportError: No module named tensorflow.python.client
Sep 21, 2018 in Python by ariaholic
• 7,340 points
3,347 views

1 answer to this question.

0 votes

I think it's a bug in Tensorflow and you should open a bug thread about it.

In any case, to workaround this issue, you can use tf.identity to create a float64_ref instead of the float64 x and pass this value as the inputs parameter.

import tensorflow as tf
import numpy as np

with tf.Session() as sess:
    x = tf.Variable(np.ones((2, 3)))
    sess.run(tf.initialize_all_variables())
    out, state = tf.nn.rnn_cell.BasicRNNCell(4)(tf.identity(x), x)
answered Sep 25, 2018 by charlie_brown
• 7,720 points

Related Questions In Python

0 votes
1 answer

tensorflow 1.5 ImportError: No module named tensorflow.python.client

Some of the modules have changed in ...READ MORE

answered Oct 5, 2018 in Python by Priyaj
• 57,300 points
738 views
0 votes
1 answer

tensorflow 1.5 ImportError: No module named tensorflow.python.client

Some of the modules have changed in ...READ MORE

answered Oct 9, 2018 in Python by Priyaj
• 57,300 points
139 views
0 votes
1 answer

Python error "ImportError: No module named pygame.locals"

You need to download and install the ...READ MORE

answered Jun 18 in Python by Greg
349 views
0 votes
1 answer

Python: ImportError: No module named Crypto.Cipher

Seems like the pycrypto package is not ...READ MORE

answered Jul 31 in Python by Hari
2,265 views
0 votes
1 answer

Python error " import requests ImportError: No module named requests"

Hi @Vasgi, for the code you're trying ...READ MORE

answered Aug 5 in Python by Layla
694 views
0 votes
1 answer
0 votes
2 answers

Python error "ImportError: No module named 'tkinter'"

sudo apt-get install python3-tk Then, >> import tkinter # ...READ MORE

answered Nov 9 in Python by Icetutor
• 160 points
899 views
0 votes
1 answer

Python error "ImportError: No module named SpeechRecognition"

Hi @Hannah, replace  import SpeechRecognition as sr with import speech_recognition ...READ MORE

answered Oct 3 in Python by Yamini
33 views
0 votes
1 answer

How to install Python MySQLdb module using pip?

It's easy to do, but hard to ...READ MORE

answered Aug 20, 2018 in Python by charlie_brown
• 7,720 points
101 views
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
217 views