缺少名为'tensorflow.python.platform'的模块。

5

我正在使用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

如何解决这个问题?


user:/home/mydirectory # 中的 # 表示 root 用户吗?如果是这样,与您的用户相比,root 可能有不同的配置。 - McAngus
你使用的是哪个操作系统?请同时指明版本号。 - Tarun Lalwani
你的发行版最近是否删除了符号链接 /{usr,}/lib -> /{usr,}/lib64,并且迁移过程不顺利? /lib 应该只用于32位程序。你能否在问题中添加 python3.6 -m site 的输出结果? - hoefling
@Harry Boy 请尝试使用root或sudo安装。然后尝试pip3 --version shekh@shekh:$ pip3 --version pip 8.1.1来自/usr/lib/python3/dist-packages (python 3.5) shekh@shekh:$ python3 Python 3.5.2(默认,Nov 12 2018,13:43:14) [GCC 5.4.0 20160609]在linux上 键入“help”、“copyright”、“credits”或“license”以获取更多信息。
- Shekh Firoz Alam
4个回答

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


2

请参考这里

您是在tensorflow目录内打开终端吗?

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

注:Original Answer翻译成"最初的回答"


0

我在一个 Windows 10 系统上遇到了类似的错误。

在那里,我有第二个 tensorflow 安装在 AppData\Roaming\Python\... 下。这个安装很可能是我之前没有清理干净的一些工作的产物,所以对我来说,删除 site-packages 目录中的内容解决了这个问题。之后,我就可以毫无问题地 import tensorflow 了。


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接