Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'tensorflow.python' with tensorflow-gpu

I wanted to have gpu-support for keras/tensorflow, thats why I installed tensorflow-gpu. So I installed tensorflow-gpu through pip:

pip install --upgrade tensorflow-gpu

This leads to this:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()
> []

Then I found this stackoverflow answer which stated I should uninstall tensorflow after installing tensorflow-gpu. This leads to this:

Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-3d00d838479b> in <module>()
----> 1 from keras import backend as K
      2 K.tensorflow_backend._get_available_gpus()

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/__init__.py in <module>()
      1 from __future__ import absolute_import
      2 
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/__init__.py in <module>()
      4 from . import data_utils
      5 from . import io_utils
----> 6 from . import conv_utils
      7 
      8 # Globally-importable utils.

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/conv_utils.py in <module>()
      7 from six.moves import range
      8 import numpy as np
----> 9 from .. import backend as K
     10 
     11 

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/__init__.py in <module>()
     82 elif _BACKEND == 'tensorflow':
     83     sys.stderr.write('Using TensorFlow backend.\n')
---> 84     from .tensorflow_backend import *
     85 else:
     86     raise ValueError('Unknown backend: ' + str(_BACKEND))

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/tensorflow_backend.py in <module>()
      4 
      5 import tensorflow as tf
----> 6 from tensorflow.python.training import moving_averages
      7 from tensorflow.python.ops import tensor_array_ops
      8 from tensorflow.python.ops import control_flow_ops

ImportError: No module named 'tensorflow.python'

Reeinstalling tensorflow with

pip install --upgrade tensorflow --no-cache

leads again to an empty array for the gpus with the code above.

Any ideas how to fix this?

like image 441
greece57 Avatar asked Mar 22 '18 15:03

greece57


People also ask

How do I fix No module named in tensorflow?

The Python "ModuleNotFoundError: No module named 'tensorflow'" occurs when we forget to install the tensorflow module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install tensorflow command.


1 Answers

This solution worked for me:

Uninstalling both CPU and GPU versions of TensorFlow and then installing only the GPU version of TensorFlow.

pip uninstall tensorflow
pip uninstall tensorflow-gpu

pip install tensorflow-gpu
like image 152
Safwan Avatar answered Oct 06 '22 06:10

Safwan