简体   繁体   中英

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?

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

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