Pycharm(Mac)上的Tensorflow导入错误

6

在这里输入图片描述

错误信息(请查看截图):

ImportError: cannot import name symbol_database

Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

Process finished with exit code 1

感谢您!
输入图像描述

下次请考虑调整一下图片的大小! - linusg
如果您直接使用Python运行它,它是否可以在PyCharm之外正常工作? - Ken Kinder
抱歉,我不明白。是图片尺寸太大了吗?谢谢。 - Ancalagon BerenLuthien
没问题,但是图片比能够显示的要大得多。加载页面需要很长时间,这可能会导致回答较少! - linusg
嗨,肯恩,我尝试了IDLE并得到了相同的错误信息。谢谢回复。 - Ancalagon BerenLuthien
可能是使用协议缓冲区的Python项目,部署问题的重复。 - wtanaka.com
1个回答

1

我尝试使用这个示例代码复现你遇到的问题:

import tensorflow as tf
hello = tf.constant('Hello, Tensorflow!')

但是我无法做到。我可以在PyCharm和命令行中运行脚本(退出代码0)而没有任何问题。
以下是tensorflow 0.8.0所需的包及其版本:
numpy==1.11.0
protobuf==3.0.0b2
six==1.10.0

我正在使用 Mac OS X 10.11.4 上的 PyCharm 社区版 2016.1.2 和 Python 2.7.10。


你是如何安装tensorflow的? 根据官网建议,你应该通过pip进行安装(https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#pip-installation)。
对于Python 2和Mac OS X,以下是安装命令: pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl

我的protobuf版本不是最新的。升级到protobuf 3.0.0b2后,问题得到解决。对于其他可能遇到类似问题的人,有一个提示:在Pycharm - 首选项 - 项目解释器中,每个软件包都显示两列:版本列和最新列。单击“+”并搜索“软件包名称”(在我的情况下为protobuf),然后必须单击“指定版本”作为所需的版本(在我的情况下为3.0.0b2.post2),然后安装。否则,版本将不会更改为3.0.0b2。 - Ancalagon BerenLuthien
有没有办法让PyCharm自动从https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl安装tensorflow?必须使用终端中的pip来安装吗? - faridghar
很可能不是。https://storage.googleapis.com/tensorflow/mac/ 不是Python软件包索引存储库。但如果是的话,您可以将其添加到PyCharm的存储库列表中。首选项>项目>项目解释器>“+”按钮>管理存储库 - HEADLESS_0NE

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