无法安装Tensorflow M

2024-10-03 15:27:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我检查了我的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

在我当前使用的虚拟环境中,我做到了:

^{pr2}$

作为标准方式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)


Tags: infrompyimportlibpackagestensorflowline
1条回答
网友
1楼 · 发布于 2024-10-03 15:27:30

更新:版本1.13引入了python3.7支持

最新的1.13版本的候选版本提供了对python3.7的支持,尤其是macos10.11和更新版本(link to 1.13.1)也提供了预编译的CPU控制盘。照常安装:

$ pip install tensorflow>=1.13

原始答案(过时)

tensorflow目前不支持Python3.7。原因是:

  • tensorflow使用async作为函数参数名,async和{}成为Python3.7中的保留关键字(正如this comment中的@phd所指出的那样)——这就是为什么会出现导入错误;

  • Python3.7更改了tensorflow使用的C API中^{}函数的返回类型:

    Changed in version 3.7: The return type is now const char * rather of char *.

这意味着必须先解决这两个问题,然后才能为python3.7&Linux/MacOS构建和发布tensorflow。您可以在此处跟踪当前状态:issue #20517。在

因此,如果需要继续使用tensorflow,那么解决方案应该是避免使用python3.7。暂时坚持使用Python3.6。在

如果您愿意从源代码生成tensorflow,请执行以下操作:There is a patch proposed to fix both issues。如果您想尝试一下,请遵循官方文档中的Install TensorFlow from Sources教程,唯一的区别在于开头:

  1. 克隆存储库

    ^{2美元
  2. 将修补程序内容复制到文件中,例如tf.patch

  3. 应用修补程序:

    $ git apply tf.patch
    
  4. 继续本教程的其余部分。

还要注意,您必须构建最新的protobuf,因为对python3.7的支持最近才添加到其中,但是没有包含在任何发布的版本中。编辑tensorflow/contrib/cmake/external/protobuf.cmake指向protobuf回购的当前HEAD。在

相关问题 更多 >