没有名为'tensorflow.python.platform'的模块

时间:2019-06-20 15:57:53

标签: linux python-3.x tensorflow pip opensuse

我正在使用python3并使用以下命令安装了tensorflow-gpu:

pip3 install tensorflow-gpu==1.13.1

并已通过以下方式检查其安装:

pip3 show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.13.1
Summary: TensorFlow is an open source machine learning framework for 
everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/lib64/python3.6/site-packages
Requires: tensorflow-estimator, keras-applications, termcolor, absl-py, six, 
astor, protobuf, wheel, keras-preprocessing, gast, grpcio, numpy, 
tensorboard
Required-by:

但是当我执行以下操作时,它给我一个错误:

user:/home/mydirectory # python3
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, 
in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: 
disable=unused-import
  File "/usr/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 25, in <module>
    from tensorflow.python.platform import self_check
ModuleNotFoundError: No module named 'tensorflow.python.platform'

我从错误中看到它正在目录中寻找tensorflow

/usr/lib/python3.6/site-packages/tensorflow

但是pip表示它已安装在

/usr/lib64/python3.6/site-packages

如何解决此问题?

4 个答案:

答案 0 :(得分:4)

Please follow below steps..
0) please login with root permission or sudo and write this command in terminal 

1)pip3 install tensorflow-gpu==1.13.1   

2)pip3 --version
  pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)   
3)shekh@shekh:~$ python3
  Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
  [GCC 5.4.0 20160609] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>>

https://www.tensorflow.org/install/pip

 for reference

tensorflow test run

答案 1 :(得分:2)

请参见https://github.com/tensorflow/tensorflow/issues/374

您是从tensorflow目录中打开终端吗?

“实际上,我遇到了这个问题,因为我试图从tensorflow repo文件夹内的python会话导入tensorflow,转到其他文件夹并启动python并导入tensorflow对我有用。”

答案 2 :(得分:0)

很多人想要输入张量流时都输入

import tensorflow as tf:

我希望这对您有帮助

答案 3 :(得分:0)

我也遇到了这个错误,并通过此命令解决了

python2

PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/dist-packages/"
export PYTHONPATH

python3

PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python3.6/dist-packages/"
export PYTHONPATH