Module imports fine from interactive, not from script

Paul Moore p.f.moore at gmail.com
Thu May 24 12:23:15 EDT 2007


On 23 May, 02:20, "Joshua J. Kugler" <jos... at eeinternet.com> wrote:
> Yes, I've read this:http://mail.python.org/pipermail/python-list/2006-August/395943.html
> That's not my problem.
>
> I installed PlanetPlanet <http://www.planetplanet.org/> via the
> package's "setup.py install" command (as root).  planet.py will not run,
> however, giving me this error:
>
> Traceback (most recent call last):
>   File "/usr/local/bin/planet.py", line 167, in ?
>     main()
>   File "/usr/local/bin/planet.py", line 124, in main
>     planet.logging.basicConfig()
> AttributeError: 'module' object has no attribute 'logging'

Your problem is that your script is called planet.py, the same as the
module you're trying to import. So from the script, "import planet"
finds the script itself (the script's directory is always added to
sys.path), and importing it as planet rather than importing the planet
module from site-packages.

The simplest fix is to not call the driver script "planet.py".

It's not exactly "terribly simple", but it is quite a common mistake
(I've certainly made it more than once...)
Paul.




More information about the Python-list mailing list