Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid syntax error while importing tensorflow in python3.7.0 #20690

Closed
tiehexue opened this Issue Jul 11, 2018 · 21 comments

Comments

Projects
None yet
@tiehexue
Copy link

tiehexue commented Jul 11, 2018

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
    MacOS High Sierra 10.13.5

  • TensorFlow installed from (source or binary):
    pip3

  • TensorFlow version (use command below):
    1.9.0

  • Python version:
    3.7.0

  • Exact command to reproduce:
    import tensorflow as tf

Describe the problem

when import tensorflow in python3 prompt, it says "SyntaxError: invalid syntax".

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114
def TFE_ContextOptionsSetAsync(arg1, async):_
^
SyntaxError: invalid syntax

Source code / logs

line 114, 115, 150 of pywrap_tensorflow_internal.py has "async" as 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

@wkpn

This comment has been minimized.

Copy link

wkpn commented Jul 11, 2018

async and await are reserved keywords in python 3.7

@smcveigh-phunware

This comment has been minimized.

Copy link

smcveigh-phunware commented Jul 11, 2018

duplicate of 20517

@murthyteja

This comment has been minimized.

Copy link

murthyteja commented Jul 28, 2018

Any update on this issue?

@mhyousefi

This comment has been minimized.

Copy link

mhyousefi commented Aug 3, 2018

This is really annoying and unacceptable! How can we resolve this issue?

@blured

This comment has been minimized.

Copy link

blured commented Aug 5, 2018

As explained above, you can edit the last file of the trace where the error occur :
/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py
and find anywhere the variable async is used and replace it with async1 so its not a python 3.7 keyword anymore. you will find those "async" variables on line 114, 115, 150
So this (for instance):
def TFE_ContextOptionsSetAsync(arg1, async):
becomes this:
def TFE_ContextOptionsSetAsync(arg1, async1):
Hope this helps !

@mhyousefi

This comment has been minimized.

Copy link

mhyousefi commented Aug 5, 2018

The error is indeed resolved after your proposed change. Thanks @blured

@Manish-rai21bit

This comment has been minimized.

Copy link

Manish-rai21bit commented Aug 7, 2018

All you need to do is change the argument "async" to something else in "/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py" in the function definition and return..

@tensorflowbutler

This comment has been minimized.

Copy link
Member

tensorflowbutler commented Aug 22, 2018

Nagging Assignee @bignamehyp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@yazeed

This comment has been minimized.

Copy link

yazeed commented Aug 27, 2018

This is weird. Needs to be fixed.

@xperiafan13-rom

This comment has been minimized.

Copy link

xperiafan13-rom commented Aug 28, 2018

some here

@bignamehyp

This comment has been minimized.

Copy link
Member

bignamehyp commented Aug 30, 2018

@yifeif can you please take a look? Thanks.

@dg1618

This comment has been minimized.

Copy link

dg1618 commented Sep 1, 2018

hi guys i have the same problem, i just did install tensor to mac sierra 12.10.6 im using python3 and

voala !!
SyntaxError: invalid syntax

import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in
File "/Users/juaporra/Library/Python/3.7/lib/python/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/juaporra/Library/Python/3.7/lib/python/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/Users/juaporra/Library/Python/3.7/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/juaporra/Library/Python/3.7/lib/python/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114
def TFE_ContextOptionsSetAsync(arg1, async):

thank you @tiehexue i did update right in pywrap_tensorflow_internal.py async for async1 , and woks !! ... the lastone was on line 155 ,

thank you so much !

@AFAgarap

This comment has been minimized.

Copy link

AFAgarap commented Sep 3, 2018

Actually, there are four lines with async: 114, 115, 154, and 155.

@dimidd

This comment has been minimized.

Copy link

dimidd commented Sep 4, 2018

This worked for me. YMMV (modify the path).
sudo sed -i 's/async/async_py3/g' /usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py

@codedsun

This comment has been minimized.

Copy link

codedsun commented Sep 5, 2018

This worked for me, but if you are changing the

def TFE_ContextOptionsSetAsync(arg1, async):
becomes this:
def TFE_ContextOptionsSetAsync(arg1, async1):

then also please change the arguments in the return type, as they are also mentioned with the 'asyc'.

@yifeif

This comment has been minimized.

Copy link
Member

yifeif commented Sep 5, 2018

I believe this should be fixed by #21202 (thanks to @bstriner) if you build from source. But looks like there won't be a python 3.7 pypi package for 1.11, cc @gunan.

@yifeif yifeif closed this Sep 5, 2018

@souravb65

This comment has been minimized.

Copy link

souravb65 commented Sep 10, 2018

I'm facing the same issue for Python 3.6.6. Is Python 3.6.6 not supported as well?

@mikeyj777

This comment has been minimized.

Copy link

mikeyj777 commented Sep 22, 2018

per the instructions above, after changing the "async" argument and returned variable names to async1, python quits on importing tensorflow.

@BTUJACK

This comment has been minimized.

Copy link

BTUJACK commented Oct 15, 2018

per the instructions above, after changing the "async" argument and returned variable names to async1 as folowing:
def TFE_ContextOptionsSetasync(arg1, async1):
return _pywrap_tensorflow_internal.TFE_ContextOptionsSetasync(arg1, async1)

def TFE_ContextSetasyncForThread(arg1, async1):
return _pywrap_tensorflow_internal.TFE_ContextSetasyncForThread(arg1, async1)

There is another problem for me:

_Traceback (most recent call last):
File "/Users/apple/Documents/ST/python/test.py", line 1, in
import tensorflow as tf
File "/usr/local/lib/python3.7/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 116, in
TFE_ContextOptionsSetasync = _pywrap_tensorflow_internal.TFE_ContextOptionsSetasync
AttributeError: module 'pywrap_tensorflow_internal' has no attribute 'TFE_ContextOptionsSetasync'

@Windsmild

This comment has been minimized.

Copy link

Windsmild commented Feb 8, 2019

This worked for me. YMMV (modify the path).
sudo sed -i 's/async/async_py3/g' /usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py

wrong syntax
should be
sudo sed -i "backupname" 's/async/async_py3/g' /usr/local/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py
and work

@wd456

This comment has been minimized.

Copy link

wd456 commented Mar 28, 2019

Hi everyone can you enlighten me I barely get Tensorflow running every time he returns these errors

Traceback (most recent call last):
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Une routine d’initialisation d’une bibliothèque de liens dynamiques (DLL) a échoué.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\WD\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Une routine d’initialisation d’une bibliothèque de liens dynamiques (DLL) a échoué.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.