无法导入tensorflow和keras

时间:2018-09-07 08:16:48

标签: python tensorflow keras

我正在尝试使用Keras,但它向mw显示了此错误:(。

Using TensorFlow backend.
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import keras
  File "C:\Python37\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Python37\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "C:\Python37\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "C:\Python37\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "C:\Python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Python37\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Python37\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                             ^
SyntaxError: invalid syntax

其他信息:

python版本:3.7。 Tensorflow版本:1.10.0。

1 个答案:

答案 0 :(得分:0)

在Github上共享的问题是async是python 3.7中的保留关键字。

您可以通过访问文件(在您的情况下为C:\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py)并将async的所有外观更改为类似async1的方式来解决此问题。

async变量位于114115150151行中。