Issue 31280: Namespace packages in directories added to path aren't importable if packages from the same namespace are in site-packages (original) (raw)
Created on 2017-08-25 21:53 by j1m, last changed 2022-04-11 14:58 by admin. This issue is now closed.
I'm having an issue importing from namespaces packages whose directories are added to sys.path and have other packages from the same namespace in site-packages. To reproduce: - Create a virtualenv and install zc.buildout in it (``envdir/bin/pip install zc.buildout``). - Run the attached script with the virtual environment (``envdir/bin/python z.py``). Note that scenarios like https://www.python.org/dev/peps/pep-0420/#id3 work fine. This seems to related to having namespace packages in site-packages, or, presumably anywhere on the default path. I've verified this with Python 3.4, 3.5, and 3.6. If y'all agree that this is a bug, then I'll attempt debug it and come up with a PR.
I think this is a function of the .pth file causing 'zc' to be in sys.modules. If I delete the .pth file, the first import of zc.m succeeds. Note that if the .pth file is in place, then: % bin/python3 Python 3.6.1 (default, Mar 24 2017, 12:50:34) [GCC 5.4.0] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> 'zc' in sys.modules True >>>
Wow, OK. It didn't occur to me to look for .pth files. (Buildout doesn't use them.) I guess this is a pip bug or misfeature. I'll head over to pypa. Thanks!