[Solved]: Invalid syntax error while importing tensorflow in python3.7.0

ERROR:

Traceback (most recent call last):  File "/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code    exec(code_obj, self.user_global_ns, self.user_ns)  File "<ipython-input-1-6266a6e0522c>", line 14, in <module>    import tensorflow as tf  File "/anaconda3/lib/python3.7/site-packages/tensorflow/__init__.py", line 22, in <module>    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import  File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>    from tensorflow.python import pywrap_tensorflow  File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>    from tensorflow.python.pywrap_tensorflow_internal import *  File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114    def TFE_ContextOptionsSetAsync(arg1, async):                                             ^SyntaxError: invalid syntax

 

Solution:

line 114, 115 and 154, 155 of pywrap_tensorflow_internal.py has “async” as a parameter which seems to be a keyword.
After changed to “async1”, importing tensorflow works.

def TFE_ContextOptionsSetAsync(arg1, async1):return _pywrap_tensorflow_internal.TFE_ContextOptionsSetAsync(arg1, async1)TFE_ContextOptionsSetAsync = _pywrap_tensorflow_internal.TFE_ContextOptionsSetAsync
Note: async and await are reserved keywords in python 3.7