ImportError:没有名为’tensorflow.python’的模块,其中包含tensorflow-gpu

我想为keras / tensorflow提供gpu支持,这就是我安装tensorflow-gpu的原因.

所以我通过pip安装了tensorflow-gpu:

pip install –upgrade tensorflow-gpu

这导致了这个:

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

然后我发现this stackoverflow answer声明我应该在安装tensorflow-gpu后卸载tensorflow.这导致了这个:

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'

重新安装tensorflow

pip install –upgrade tensorflow –no-cache

使用上面的代码再次引导gpus的空数组.

任何想法如何解决这一问题?

最佳答案 这个解决方案对我有用:

卸载TensorFlow的CPU和GPU版本,然后仅安装GPU版本的TensorFlow.

pip uninstall tensorflow
pip uninstall tensorflow-gpu

pip install tensorflow-gpu
点赞