无法安装Tensorflow Mac [英] Can't install Tensorflow Mac
问题描述
我检查了我的pip3& python3版本:
I checked my pip3 & python3 version:
(tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ pip3 -V
pip 10.0.1 from /Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip (python 3.7)
(tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ python3 -V
Python 3.7.0
在当前正在使用的虚拟环境中,我这样做了:
In the virtual environment I am currently using I did:
pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl
pip3 install tensorflow
作为标准方式输出以下消息:
As the standard way pip3 install tensorflow
output the following message:
could not find a version that satisfies the requirement tensorflow (from versions: )
使用第一种方法说明安装后:
After installed using the first method explained:
(tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ python3
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114
def TFE_ContextOptionsSetAsync(arg1, async):
^
SyntaxError: invalid syntax
出了什么问题?我可以下载其他软件包,例如numpy,但没有Tensorflow. (MacOS 10.13.4)
What is the issue? I can download other packages such as numpy but no Tensorflow. (MacOS 10.13.4)
推荐答案
更新:1.13版引入了对Python 3.7的支持
1.13版本的最新候选版本提供了对Python 3.7的支持,特别是预编译的CPU轮也可用于MacOS 10.11和更高版本(
Python 3.7更改了 < Python 3.7 changed the return type of 在3.7版中进行了更改:现在,返回类型为
这意味着必须为Python 3.7& amp;构建并发布 This means both issues must be fixed before 因此,如果您需要继续使用 The solution hence would be avoiding Python 3.7 if you need to continue working with 如果您愿意从源代码构建 If you are willing to build 克隆存储库 Clone the repository
将补丁内容复制到文件中,例如 应用补丁程序: 继续本教程的其余部分. Proceed with the rest of the tutorial. 还请注意,您必须构建最新的 Also note that you will have to build the latest 这篇关于无法安装Tensorflow Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
原始答案(已过时)
tensorflow
目前不支持Python 3.7.原因是:
Original answer (outdated)
tensorflow
does not support Python 3.7 at the moment. The reason for this is that:
tensorflow
uses async
as function parameter name, and async
and await
became reserved keywords in Python 3.7 (as pointed by @phd in this comment) - this is why you're getting the import error;tensorflow
使用的C API中的c6> 函数:PyUnicode_AsUTF8AndSize
function in the C API used by tensorflow
:
const char *
而不是char *
.tensorflow
之前,必须解决这两个问题. Linux/MacOS.您可以在此处跟踪当前状态:问题#20517 .tensorflow
can be built and released for Python 3.7 & Linux/MacOS. You can track the current status here: issue #20517.tensorflow
,该解决方案将避免使用Python 3.7.暂时坚持使用Python 3.6.tensorflow
. Stick with Python 3.6 for the time being.tensorflow
:有一个提出了解决这两个问题的补丁程序.如果您想尝试一下,请遵循官方文档中的从源代码安装TensorFlow 教程,唯一的区别在于开始:tensorflow
from source: There is a patch proposed to fix both issues. If you want to try it out, follow the Install TensorFlow from Sources tutorial from the official docs, the only difference being on the beginning:
$ git clone https://github.com/tensorflow/tensorflow
tf.patch
$ git apply tf.patch
protobuf
,因为最近已添加了对Python 3.7的支持,但未包含在任何发行版中.编辑tensorflow/contrib/cmake/external/protobuf.cmake
指向protobuf
存储库的当前HEAD
.protobuf
, as the support for Python 3.7 was added to it lately, but is not contained in any released version. Edit tensorflow/contrib/cmake/external/protobuf.cmake
to point to the current HEAD
of the protobuf
repo.