无法安装Tensorflow Mac [英] Can't install Tensorflow Mac

查看:227
本文介绍了无法安装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和更高版本(


原始答案(已过时)

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;

Python 3.7更改了 <tensorflow使用的C API中的c6> 函数:

Python 3.7 changed the return type of PyUnicode_AsUTF8AndSize function in the C API used by tensorflow:

在3.7版中进行了更改:现在,返回类型为const char *而不是char *.

这意味着必须为Python 3.7& amp;构建并发布tensorflow之前,必须解决这两个问题. Linux/MacOS.您可以在此处跟踪当前状态:问题#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:有一个提出了解决这两个问题的补丁程序.如果您想尝试一下,请遵循官方文档中的从源代码安装TensorFlow 教程,唯一的区别在于开始:

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:

  1. 克隆存储库

  1. 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屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆