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

[v3.0.0-beta] Python 3 can't import properly related proto files #762

Closed
omikronsc opened this issue Aug 27, 2015 · 3 comments
Closed

[v3.0.0-beta] Python 3 can't import properly related proto files #762

omikronsc opened this issue Aug 27, 2015 · 3 comments

Comments

@omikronsc
Copy link

Hello!

I have two proto files core.proto and items.proto, items.proto import core.proto. They are generated into project's subdirectory src_gen. Problem is that in generated Python code there is import in items_pb2.py:

    import core_pb2 as core__pb2

It doesn't work in Python 3 since it's relative import and syntax for relative import changed in Python 3. It should be (at the begining for python 2.5+ compatibility):

from __future__ import absolute_import 

And replace import:

    from . import core_pb2 as core__pb2

This is how I feel it should solved but I might be unaware of some other method. Is there any other solution?

@xdmiodz
Copy link

xdmiodz commented Nov 19, 2015

Looks similar to #881, I think have a workaround/possible solution for the issue there

@omikronsc
Copy link
Author

Actually I used another trick to solve this issue. I run 2to3 on src_gen folder after every invoke to protoc and everything works properly both on Python 2.7 and 3

But it is what it is - a workaround.

@haberman
Copy link
Member

I think this is a duplicate of #1491

adellahlou pushed a commit to adellahlou/protobuf that referenced this issue Apr 20, 2023
rinarakaki pushed a commit to rinarakaki/protobuf that referenced this issue Aug 30, 2023
bithium pushed a commit to bithium/protobuf that referenced this issue Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants