Python tensorflow安装问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35252888/
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-08-19 16:11:31  来源:igfitidea点击:

tensorflow installation problems

pythontensorflow

提问by jolly

I tried installing tensorflow on my ubuntu 14.04 64bit machine:

我尝试在我的 ubuntu 14.04 64 位机器上安装 tensorflow:

sudo pip2 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl

for python 2.7

对于蟒蛇 2.7

When I run import tensorflow as tfin the console I get error

当我import tensorflow as tf在控制台中运行时出现错误

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.

导入张量流时出错。除非您使用 bazel,否则您不应尝试从其源目录导入 tensorflow;请退出 tensorflow 源代码树,然后从那里重新启动您的 Python 解释器。

Google didn't provide a good answer to this, any thoughts?

谷歌没有提供一个很好的答案,有什么想法吗?

回答by fedorSmirnov

I had a similar problem. The error message also contained the line "ImportError: No module named google.protobuf". As mentioned here: https://github.com/tensorflow/tensorflow/issues/1415, a workaround for this problem is to create an empty __init_.py file in the tensorflow/google directory, where you should also have the protobuf folder. Hope this helps.

我有一个类似的问题。错误消息还包含“ImportError: No module named google.protobuf”这一行。如此处所述:https: //github.com/tensorflow/tensorflow/issues/1415,此问题的解决方法是在 tensorflow/google 目录中创建一个空的 __init_.py 文件,您还应该在其中拥有 protobuf 文件夹。希望这可以帮助。

回答by Nils Cao

Before you type command pythonin terminal, your workspace shouldn't be the directory which contain the tensorflow-0.6.0-cp27-none-linux_x86_64.whl. i.e. your workspace should be different from the directory where tensorflow-0.6.0-cp27-none-linux_x86_64.whl is.

python在终端中键入命令之前,您的工作区不应是包含 tensorflow-0.6.0-cp27-none-linux_x86_64.whl 的目录。即您的工作区应该与 tensorflow-0.6.0-cp27-none-linux_x86_64.whl 所在的目录不同。

回答by Tian

Strongly suggest you to use virtualenv. I have been suffering in installing tensorflow as well as its dependencies for weeks until I learn about virtualenv. You can follow the official tutorial to install it. (https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html) And it comes with all the library that you are likely to use. Also, you can modify your environment in your Python IDE. Then you don't have to active and deactive virtualenv every time you use it.ery Very convenient !

强烈建议您使用 virtualenv。几周以来,我一直在安装 tensorflow 及其依赖项,直到我了解了 virtualenv。可以按照官方教程安装。( https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html) 它附带了您可能会使用的所有库。此外,您可以在 Python IDE 中修改您的环境。那你就不用每次使用都去激活和去激活 virtualenv 了。 非常方便!

回答by jasekp

I would recommend using Anaconda. It makes it easy to install all dependencies needed (most are automatically installed) and there are multiple options for installing tensorflow.

我建议使用Anaconda。它可以轻松安装所需的所有依赖项(大多数是自动安装的),并且有多种安装 tensorflow 的选项。

conda install tensorflow

or

或者

conda install tensorflow-gpu

回答by The Puternerd

You cannot import tensorflow whilst you are in the tensorflow source directory. Change Directory i.e. cd ..first before running python.

当您在 tensorflow 源目录中时,您无法导入 tensorflow。cd ..在运行python之前首先更改目录。

I've emphasized the key part of your error: "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."

我已经强调了您错误的关键部分:“导入 tensorflow 时出错。除非您使用 bazel,否则您不应尝试从其源目录导入 tensorflow;请退出 tensorflow 源代码树,并从那里重新启动您的 python 解释器。”

回答by Neil Deshmukh

Follow these steps:

按着这些次序:

sudo apt-get install python-pip python-dev

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl

sudo pip install --upgrade $TF_BINARY_URL

And then run python. It should work.

然后运行python。它应该工作。

回答by gunan

You will see this issue if you start python when you are working inside the source tree of tensorflow. (wherever you cloned the git repository) Python gets confused about what to import when you run "import tensorflow" (the one in your directory or the system installed one). That is what the error message is trying to say.

如果你在 tensorflow 的源代码树中工作时启动 python,你会看到这个问题。(无论您在何处克隆 git 存储库)当您运行“导入 tensorflow”(您的目录中的那个或系统安装的那个)时,Python 都会对要导入的内容感到困惑。这就是错误消息试图表达的意思。

Simply change to your home directory, or a new empty directory and it should work.

只需更改到您的主目录或新的空目录,它应该可以工作。

回答by Engineero

I ran in to a similar issue and it turned out it was because the protobuf dependency wasn't met, or there was an issue with protobuf. I would uninstall protobuf:

我遇到了类似的问题,结果证明是因为未满足 protobuf 依赖关系,或者 protobuf 存在问题。我会卸载protobuf:

>> sudo pip uninstall protobuf

Then re-install:

然后重新安装:

>> sudo pip install --upgrade protobuf

If that doesn't work, try uninstalling and re-installing both protobuf and tensorflow. If you are building from source, check out this issue on GitHub

如果这不起作用,请尝试卸载并重新安装 protobuf 和 tensorflow。如果您是从源代码构建,请在 GitHub 上查看此问题

回答by Rishabh Gupta

The problem is with your tensorflow installation version and environmental configuration. I have also faced same issue, as I had installed tensorflow for Python version 3.5 while my system has 3.6.

问题出在你的tensorflow安装版本和环境配置上。我也遇到了同样的问题,因为我为 Python 3.5 版安装了 tensorflow,而我的系统有 3.6。

Select the correct wheel for your installation. https://pypi.python.org/pypi/tensorflow

为您的安装选择正确的车轮。 https://pypi.python.org/pypi/tensorflow

It should work.

它应该工作。

回答by m0z4rt

I recommend you use Anaconda, it's really helpful for ML and data science job.

我建议您使用Anaconda,它对 ML 和数据科学工作非常有帮助。