ImportError:没有名为“ tensorflow.python”的模块; 'tensorflow'不是包

时间:2019-12-18 15:09:58

标签: python tensorflow keras

问题:

我正确安装了kerastensorflow。尽管它们都已安装,但是在import keras时遇到以下错误:

  File "/root/PycharmProjects/DeepLearning/paper/test.py", line 1, in <module>
    import keras.activations
  File "/home/saeed/.conda/envs/py35/lib/python3.5/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/home/saeed/.conda/envs/py35/lib/python3.5/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/home/saeed/.conda/envs/py35/lib/python3.5/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/home/saeed/.conda/envs/py35/lib/python3.5/site-packages/keras/backend/__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "/home/saeed/.conda/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
    from tensorflow.python.framework import ops as tf_ops
ImportError: No module named 'tensorflow.python'; 'tensorflow' is not a package

我的努力:

我尝试了以下解决方案123,但未找到结果。还要卸载kerastensorflow,然后重新安装,但没用。

问题出在哪里?

  

系统:Ubuntu 18.04.1 LTS

     

Python :3.5

     

Keras :2.2.2

     

tensorflow :1.10.0

2 个答案:

答案 0 :(得分:1)

Pip3 install命令而不是pip install应该可以解决问题。

答案 1 :(得分:0)

由于您使用的是Python3 +,因此我将使用pip3 install tensorflow==2.0.0

from tensorflow.keras import <whatever-module-you-need>

Tensorflow是Keras API。您可以从任何一个导入!