简体   繁体   中英

ImportError: No module named 'tensorflow.python'; 'tensorflow' is not a package

Problem:

I install keras and tensorflow correctly. Although both of them installed but i encounter with the following error when 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

My efforts:

I try these solutions 1 , 2 , 3 but no result found. Also uninstall keras and tensorflow and install again but useless.

Where is the problem?

System : Ubuntu 18.04.1 LTS

Python : 3.5

Keras : 2.2.2

Tensorflow : 1.10.0

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

Since you are using Python3+, I would use pip3 install tensorflow==2.0.0

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

Tensorflow is the Keras API. You could import from either!

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