New submission from Vadim Kantorov:

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

----------
components: Extension Modules
messages: 248948
nosy: Vadim Kantorov
priority: normal
severity: normal
status: open
title: Module location load order is not respected if pkg_resources is imported 
and a namespace is declared
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to