[issue2751] Regression for executing packages

Nick Coghlan report at bugs.python.org
Mon Oct 13 11:20:14 CEST 2008


Nick Coghlan <ncoghlan at gmail.com> added the comment:

(Adding some additional details regarding the reasons why this became an
error again in 2.6)

The ImportError when attempting to execute a package was lost during the
conversion from the C-based implementation in 2.4 to the runpy module
based implementation as part of 2.5. Packages really aren't meant to be
executable with -m - it gets messy since__init__ is able to modify the
way module lookups work within the package, and there are various other
package specific details related to relative imports that don't apply
when dealing with normal modules.

That said, executing "-m pkg.__init__" with Python 2.6 will generally
have the same effect as doing "-m pkg" with Python 2.5 (it keeps the
import machinery happy since the package gets imported normally first,
and so long as pkg.__init__ can cope with being first imported normally
for the package initialisation and then run as '__main__' it should also
work as a script).

Anyone that would like to see the ability to execute packages restored
should feel free to create a RFE issue for it, but it would take a
fairly detailed analysis of the import system to convince me that doing
so doesn't break any of the interpreter internals.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2751>
_______________________________________


More information about the Python-bugs-list mailing list