Error in python after 'import tensorflow': TypeError: __init__() got an unexpected keyword argument 'syntax'

匿名 (未验证) 提交于 2019-12-03 03:06:01

问题:

I installed TensorFlow on my Ubuntu 15.10 machine as instructed for CPU only:

$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

Then when I run the Python REPL and import tensorflow, I get:

$ python Python 2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last):   File "", line 1, in    File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in     from tensorflow.python import *   File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in      from tensorflow.core.framework.graph_pb2 import *   File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in      from tensorflow.core.framework import attr_value_pb2 as     tensorflow_dot_core_dot_framework_dot_attr__value__pb2   File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in      from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2   File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in      from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2   File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in      serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto \x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3') TypeError: __init__() got an unexpected keyword argument 'syntax'

I have the Ubuntu protobuf-compiler package installed and it's version 2.6.1-1.2

回答1:

Several users have reported issues that arise when an older version of protobuf is installed.

TensorFlow requires (and uses a copy of) protobuf-3.0.0a4. However it seems to be conflicting with your installed version (perhaps due to how the PYTHONPATH environment variable is configured on your system?). Can you try uninstalling the python-protobuf package if it is installed, and then seeing if TensorFlow starts correctly?

Some users have had success when using a virtualenv. For instructions on installing TensorFlow into a virtualenv, see the getting started guide.



回答2:

This github comment solved my problem.

In short, you'll need protobuf>=3.0 installed to make tensorflow work.

First uninstall whichever protobuf you have, then pip install 'protobuf>=3.0.0a3'.

It's not just an issue for Ubuntu, Mac OS also has a similar issue.



回答3:

It worked for me:

pip uninstall protobuf pip uninstall tensorflow brew uninstall protobuf pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl  import google.protobuf >>> print google.protobuf.__version__ 3.0.0a4 >>> import tensorflow


回答4:

I got the same error while running on the python version 2.7. But everything went fine when i ran it using python version 3.

Try the following commands on bash shell:

python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux  Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow >>> exit()

It worked for me.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!