breaks the ability to load the main Python distribution's as "__main__"

Create issue
Issue #321 new
Uzume created an issue

Python's main distribution has provided a module for a long time. It has also been automatically imported for a long time. Since early on (at least 2.0) it has had code that allows it to be loaded as "main" for testing and user feedback on the sys.path, etc. Python on has had the ability to load a library module as "main" since 2.4 with the -m command-line option. This feature was updated with PEP 338 in 2.5 (to support PEP 302 import hooks).

Distribute's module shadows or hides the main Python module that comes with Python distributions. In order to ensure the main's functionality is maintained distribute's performs some trampoline tricks in its __boot().

Unfortunately, these trampoline tricks to not support loading Python's main module as "main" and thus breaks that functionality (for users to understand their sys.path including, site-packages, user-site-packages and other functionality as time goes on).

This should be fixed. Since it seems distribute's main reason for wanting to do this appears to be obtain auto-import loading and since Python's main module has provided the ability to import a "sitecustomize" module since early on (at least 2.0), I recommend the fix be oriented around moving distribute's functionality that needs auto-import loading to use sitecustomize.

I am unsure if this affects setuptools before the fork or not.

Issue found in Debian squeeze package that contains distribute 0.6.14 but appears to still exist in latest code (based upon inspection).

Comments (7)

  1. Uzume reporter

    It seems the markup here took the leading and trailing double underscores out of the Python main module name identifier (making it underlined).

  2. Uzume reporter

    Another option for auto-import loading would be to add a .pth file to the a site-packages directory and have that import a module that does your auto-initialization. This functionality is available within since 2.1 (patched here: That might be better than mucking with sitecustomize as such is documented to be used by a site administrator and there is potential for further conflicts like the current situation.

    The only down-side to this is you are not guaranteed is done updating sys.path when your module is imported via a .pth file.

  3. Jason R. Coombs

    So the issue is that with distribute installed, the command "python -m site" doesn't output anything, but you expect it instead to output details about the Python installation (presumably how Python behaves without distribute installed)?

  4. Uzume reporter

    Yes--exactly. You could try somehow continuing to shadow the main and implement a means to punt to it when loaded as the main module (perhaps using runpy) but methinks life would be better not shadowing a module in the in the main Python distribution.

  5. g2p

    After a bit of archeology… PJEby renamed to in 2006, probably to avoid this kind of interference, but distribute was already forked by the time (hg history starts in 2005). It's still used by the easy_install command, which copies it somewhere as (into every dir in site.path, possibly, or into the egg dirs it creates according to one bug report), though I doubt that is for any useful purpose (apparently it's there to put eggs a bit earlier in path resolution order). If we rename it, pip users will never have to see it.

  6. Uzume reporter

    Yes, it was clear to me that such a misdesign would have other problematic side-effects but I just reported how I found it.

  7. Log in to comment