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,320 points
1,959 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,710 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
• 56,160 points
384 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
• 56,160 points
101 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
34 views
0 votes
1 answer

ImportError: No module named requests

Requests is not available for use by ...READ MORE

answered Jun 26, 2018 in Python by Hamartia's Mask
• 1,580 points
569 views
0 votes
2 answers
0 votes
1 answer
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,120 points

edited Aug 8, 2018 by Omkar 398 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,500 points
613 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,710 points
72 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,710 points
84 views