Skip to content

Python 3 SyntaxError #882

Closed
Closed

Description

@dvenza

After doing a pip3 install protobuf, when I try to use the package I get this SyntaxError:

File "/usr/local/lib/python3.4/dist-packages/google/protobuf/reflection.py", line 68, in <module>
    from google.protobuf.internal import python_message
File "/usr/local/lib/python3.4/dist-packages/google/protobuf/internal/python_message.py", line 848
    except struct.error, e:

Why there is a package for python3, if python3 is not supported?

Activity

  1. MH-L commented on Oct 18, 2015

    @MH-L

    Is this the full stack trace? What is the error message of the exception?

  2. nongiach commented on Oct 23, 2015

    @nongiach

    it's not a exception, it's syntax error !!! it should be "except (struct.error, e):" , I tried to correct it myself but there are too many error of syntax (syntax python2 in python3 package). Thx to fix it plz

  3. dvenza commented on Oct 23, 2015

    @dvenza
    Author

    You can manually convert with 2to3 all the files by hand, but why is this package advertised as python 3 compatible and why is it available via pip for python 3?

  4. nmoadev commented on Jan 8, 2016

    @nmoadev

    This issue happens for me too. Simple test is to confirm is just to run a compiled protocol buffer python file directly. Same syntax error occurs. Pip freeze shows 'protobuf==2.6.1'

  5. xfxyjwf commented on Jan 8, 2016

    @xfxyjwf
    Contributor

    That last stable release (2.6.1) doesn't support python3. For python3, you need to install the latest beta versions:

    $ pip3 install protobuf==3.0.0b2

    Since it's beta, it's not automatically picked up by "pip3 instal protobuf" and you need to set the version number explicitly.

  6. ZubairKhan001 commented on Feb 9, 2018

    @ZubairKhan001

    i have compiled caffe on Ubuntu 16.04 LTS both with python 2 and python, it is really a hectic process for beginners, for caffe with python 2.7 make sure that your /.local/lib/python2.7/site-packages only contains a version same as you protoc version. protoc version can be checked by entering
    protoc --version
    for me i got problems with python 2.7 because by mistake i installed protbuf 3.0 alpha in python 2.7 site packages, so there was a protobuf error after removing it from python 2.7 site packages everything worked fine
    also install python-dev version
    apt-get install the python3.x-dev
    and for python 3.5 make sure you have python 3.0 alpha, if you have both python 2.7 and python 3.x in the system use pip3 otherwise use pip

    pip3 install protobuf==3.0.0-alpha-3

    or another protobuf such as 3.5 version of protobuf.
    also do this
    pip3 install python-dateutil --upgrade
    after that do
    make clean
    make all
    make runtest
    make pycaffe
    after performing make all make runtest steps don't forget to do that
    sudo ldconfig

    hope everything works OK for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions