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

Use pkgutil to allow successfully work with python packages that contain google or google/protobuf #859

Closed
tbetbetbe opened this issue Oct 6, 2015 · 3 comments

Comments

@tbetbetbe
Copy link

google/protobuf is a key dependency of python grpc.

Shortly, gRPC-based will be published that contain either a top-level 'google' package, and in some cases other modules in the google/protobuf package.

At the moment using, any of these other packages will generally fail because the protobuf package is installed

  • the other google package will contain modules with the google package (sometimes in google/protobuf)
  • when the protobuf package is installed, both google and google/protobuf end up being resolved to the protobuf package
  • other paths on the sys.path are not searched

The result is importing modules from the other packages ends with 'No module named logging.v1' for snippets like:

from google.logging.v1 import ....

There is well-known way to resolve this using pkgutil

  • Use pkgutil.extend_path inside the init.py of the google and google/protobuf packages
    E.g,
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

A good online resource explaining this use of pkgutil is available at pymotw:pkgutil

@haberman
Copy link
Member

Is this the same problem as described in #713 ?

This is one of those issues that I'd be happy to accept a PR for. The only reason I haven't fixed it already is because the Python packaging ecosystem is (to me) really complicated and subtle, and so it often takes a lot of background research for me to determine exactly what the right fix is.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jan 21, 2016

Same issue here: #1153

@haberman
Copy link
Member

haberman commented Mar 5, 2016

Closing in favor of #1296

@haberman haberman closed this as completed Mar 5, 2016
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

3 participants