带有 Eclipse 的 TensorFlow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34883885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:01:25  来源:igfitidea点击:

TensorFlow with Eclipse

pythoneclipsemacospydevtensorflow

提问by Eddy

I'm trying to run the TensorFlow Python examples for with Eclipse Mars for Mac OS X, but I'm getting the following error:

我正在尝试使用 Eclipse Mars for Mac OS X 运行 TensorFlow Python 示例,但出现以下错误:

Unresolved import: tensorflow.python.platform 

The error is raised on the 3rd line:

错误出现在第 3 行:

from __future__ import absolute_import
from __future__ import print_function

import tensorflow.python.platform

I'm new to Python and TensorFlow. I'm using PyDev for Eclipse. I read somewhere that I can add code to the "External Libraries" folder but I'm not sure where the TensorFlow library is.

我是 Python 和 TensorFlow 的新手。我在 Eclipse 中使用 PyDev。我在某处读到可以将代码添加到“外部库”文件夹中,但我不确定 TensorFlow 库在哪里。

I installed TensorFlow following the installation directions on the TensorFlow website.

按照 TensorFlow 网站上的安装说明安装了 TensorFlow

What am I missing?

我错过了什么?

回答by mrry

It sounds like you are running into a problem with your Python environment. The easiest way to deal with this is to follow these steps:

听起来您的 Python 环境有问题。处理此问题的最简单方法是执行以下步骤:

  1. Install TensorFlow into a virtualenv, by following the instructions here. This avoids the need to acquire root privileges, and makes it easier to experiment with different versions of TensorFlow. (It also avoids conflicts with other system-installed versions of different libraries.)

  2. Set up PyDev to use your new virtualenv, by following step 5 onwards in this guide. This involves setting up a new "interpreter" whose library will be the set of libraries in the virtualenv. You may need to recreate your Eclipse project to use this interpreter.

  1. 按照此处的说明将 TensorFlow 安装到 virtualenv 中。这避免了获取 root 权限的需要,并且可以更轻松地尝试不同版本的 TensorFlow。(它还避免了与不同库的其他系统安装版本发生冲突。)

  2. 按照本指南中的第 5 步开始,设置 PyDev 以使用您的新 virtualenv 。这涉及设置一个新的“解释器”,其库将是 virtualenv 中的库集。您可能需要重新创建 Eclipse 项目才能使用此解释器。

回答by amr koura

  1. install tensorflow.
  2. in eclipse , assume you have pydev installed, go to preferences>pydev>python interpreter.
  3. in the libraries tab add the path to the lib folder of your tensorflow lib folder.
  1. 安装张量流。
  2. 在 eclipse 中,假设您已经安装了 pydev,请转到首选项>pydev>python 解释器。
  3. 在库选项卡中,将路径添加到 tensorflow lib 文件夹的 lib 文件夹中。

here is screenshot: enter image description here

这是截图: 在此处输入图片说明

回答by Gal_M

I also had import issues. I fixed it by creating a new project and specifying interpreter as ~/tensorflow/lib/python2.7

我也有进口问题。我通过创建一个新项目并将解释器指定为 ~/tensorflow/lib/python2.7 来修复它

Eclipse seems to then point to the right interpreter and offers to import other relevant files - result is similar to answer above.

Eclipse 似乎然后指向正确的解释器并提供导入其他相关文件 - 结果类似于上面的答案。

The answer from @mrry above was helpful - only the link to the 5 step guide seems to be unavailable. Hope this helps!

上面@mrry 的回答很有帮助 - 只有 5 步指南的链接似乎不可用。希望这可以帮助!

Screenshot

截屏