无法安装 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 和更新版本 (链接到 1.13.1).照常安装:
$ pip install tensorflow>=1.13
<小时>
原始答案(过时)
tensorflow
目前不支持 Python 3.7.这样做的原因是:
Original answer (outdated)
tensorflow
does not support Python 3.7 at the moment. The reason for this is that:
tensorflow
使用async
作为函数参数名,async
和await
在Python 3.7(正如@phd 在此评论中指出的那样)-这就是为什么你重新收到导入错误;
tensorflow
usesasync
as function parameter name, andasync
andawait
became reserved keywords in Python 3.7 (as pointed by @phd in this comment) - this is why you're getting the import error;
Python 3.7 更改了 <tensorflow
使用的C API中的code>PyUnicode_AsUTF8AndSize函数:
Python 3.7 changed the return type of PyUnicode_AsUTF8AndSize
function in the C API used by tensorflow
:
在 3.7 版更改:返回类型现在是 const char *
而不是 char *
.
Changed in version 3.7: The return type is now
const char *
rather ofchar *
.
这意味着必须先解决这两个问题,然后才能为 Python 3.7 & 构建和发布 tensorflow
Linux/MacOS.您可以在此处跟踪当前状态:issue #20517.
This means both issues must be fixed before 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.
The solution hence would be avoiding Python 3.7 if you need to continue working with tensorflow
. Stick with Python 3.6 for the time being.
如果您愿意从源代码构建 tensorflow
:有一个补丁可以解决这两个问题.如果您想尝试一下,请按照官方文档中的 Install TensorFlow from Sources 教程进行操作,唯一的区别在于开头:
If you are willing to build 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:
克隆存储库
Clone the repository
$ git clone https://github.com/tensorflow/tensorflow
将补丁内容复制到文件中,例如tf.patch
应用补丁:
$ git apply tf.patch
继续本教程的其余部分.
Proceed with the rest of the tutorial.
另请注意,您必须构建最新的 protobuf
,因为最近添加了对 Python 3.7 的支持,但未包含在任何发布版本中.编辑 tensorflow/contrib/cmake/external/protobuf.cmake
以指向 protobuf
存储库的当前 HEAD
.
Also note that you will have to build the latest 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.
这篇关于无法安装 Tensorflow Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!