[Distutils] How to detect a namespace packages?

PJ Eby pje at telecommunity.com
Mon Aug 26 22:48:30 CEST 2013

On Mon, Aug 26, 2013 at 6:36 AM, Hartmut Goebel
<h.goebel at crazy-compilers.com> wrote:
> Hi,
> I'm one of the developers of www.pyinstaller.org, a tool for creating
> stand-alone executables.
> We need to reliable detect if a package is a namespace package (nspkg).
> For each namespace, we need to add an empty fake-module into our
> executable to keep the import mechanism working. This has to work in all
> versions of Python starting with 2.4.
> nspkgs set up via a nspkg.pth-file are detected by being in sys.modules,
> but imp.find_module() files.
> For nspkgs using __init__.py-files (which use
> pkg_resources.declare_namespace() or pkgutil.extend_path()) I have no
> clue how to detect them.
> I tried to query meta-information using pkgresources, but I did not find
> a solution.
> Any help?

Setuptools package metadata includes a namespace_packages.txt file
with this information:


This won't help you with PEP 420 namespace packages (3.3+), unless
someone declares them, and likewise it won't help if somebody uses the
dynamic APIs without any declaration.  But at least it'll give you the
declared ones.

More information about the Distutils-SIG mailing list