无法安装Tensorflow Mac
我检查了我的pip3和python3版本:
(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
在虚拟环境中,我目前正在使用:
pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl
作为标准方法,pip3 install tensorflow
输出以下消息:
could not find a version that satisfies the requirement tensorflow (from versions: )
安装后使用第一种方法说明:
(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)
-
更新:1.13版引入了对Python 3.7的支持
1.13版本的最新候选版本带来了Python 3.7支持,特别是预编译的CPU轮也可用于MacOS
10.11和更高版本(链接到1.13.1)。照常安装:$ pip install tensorflow>=1.13
原始答案(已过时)
tensorflow
目前不支持Python 3.7。原因是:-
tensorflow
用途async
为功能参数的名称,async
并await
成为(由@phd在尖的保留关键字在Python 3.7此评论) -这就是为什么你得到的导入错误; -
Python 3.7更改了
PyUnicode_AsUTF8AndSize
C API使用的函数的返回类型tensorflow
:
改变在3.7版本:返回类型现在是
const char *
相当的char *
。这意味着必须先解决两个问题,然后
tensorflow
才能针对Python 3.7和Linux /
MacOS构建和发布它们。您可以在此处跟踪当前状态:问题#20517。因此,如果需要继续使用,解决方案将避免使用Python 3.7
tensorflow
。暂时坚持使用Python 3.6。如果您愿意
tensorflow
从源代码构建:建议使用一个补丁来解决这两个问题。如果您想尝试一下,请遵循官方文档中的“从源代码安装TensorFlow”教程,唯一的区别是在开始时:-
克隆存储库
$ git clone https://github.com/tensorflow/tensorflow
-
将补丁内容复制到文件中,例如
tf.patch
-
应用补丁:
$ git apply tf.patch
-
继续本教程的其余部分。
还要注意,由于最近
protobuf
已添加了对Python
3.7的支持,但您尚未构建任何最新版本,因此必须构建最新的。编辑tensorflow/contrib/cmake/external/protobuf.cmake
指向当前HEAD
的的protobuf
回购。 -