This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Vadim Kantorov
Recipients Vadim Kantorov
Date 2015-08-21.10:18:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1440152333.17.0.123323582496.issue24907@psf.upfronthosting.co.za>
In-reply-to
Content
If module's __init__.py contains "__import__('pkg_resources').declare_namespace(__name__)", the module is not loaded, even though it's located in the current directory and should mask other modules.

Originally I stumbled upon this issue while installing a new version of Google Protobuf. But here's a simpler repro:

$ python -c 'import json; print json.__file__'
/usr/lib/python2.7/json/__init__.pyc

$ mkdir json; echo "print 'test'" > json/__init__.py
$ python -c 'import json; print json.__file__'
test
json/__init__.py

$ echo "__import__('pkg_resources').declare_namespace(__name__); print 'test'" > json/__init__.py
$ python -c 'import json; print json.__file__'
test
/usr/lib/python2.7/json/__init__.pyc

For Protobuf, if you build Python bindings from sources, the google/__init__.py will contain exactly "__import__('pkg_resources').declare_namespace(__name__)" and it prevents the freshly-built module from being loaded, even if the module egg is at the first place in sys.path. So an older version gets loaded and it screws things up.

Ubuntu 14.10, Python 2.7.8
History
Date User Action Args
2015-08-21 10:18:53Vadim Kantorovsetrecipients: + Vadim Kantorov
2015-08-21 10:18:53Vadim Kantorovsetmessageid: <1440152333.17.0.123323582496.issue24907@psf.upfronthosting.co.za>
2015-08-21 10:18:53Vadim Kantorovlinkissue24907 messages
2015-08-21 10:18:52Vadim Kantorovcreate