导入tensorflow 1.8.0时出现语法错误如何解决?

问题描述 投票:0回答:1

我将张量流导入为:

import tensorflow as tf 

并收到此错误:

Traceback (most recent call last):
  File "C:\Users\USER\Downloads\import_tensorflow.py", line 1, in <module>
    import tensorflow as tf
  File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                         ^^^^^
SyntaxError: invalid syntax

pip list
pip show
的结果表明我的电脑上安装了tensorflow...

点列表:

tensorflow         1.8.0 

pip 显示张量流:

Version: 1.8.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0 ```
python tensorflow pip module python-import
1个回答
0
投票

这是旧版本的一个bug,使用

async
作为变量名,在3.7版本中成为Python关键字。

只需安装最新版本的 Tensorflow(当前为 2.15.0.post1),这个问题就应该得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.