Module imports fine from interactive, not from script

J

Joshua J. Kugler

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'

But, from interactive session:

jkugler@europa:~/www$ ls -l # to show that the modules are not in the
current dir
total 20
-rw-r--r-- 1 jkugler jkugler 2247 2007-05-22 15:26 atom.xml.tmpl
-rw-r--r-- 1 jkugler jkugler 2089 2007-05-22 15:25 index.html.tmpl
-rw-r--r-- 1 jkugler jkugler 564 2007-05-22 15:43 planet.ini
-rw-r--r-- 1 jkugler jkugler 1128 2007-05-22 15:26 rss10.xml.tmpl
-rw-r--r-- 1 jkugler jkugler 838 2007-05-22 15:26 rss20.xml.tmpl
jkugler@europa:~/www$ python
Python 2.4.3 (#2, Oct 6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.<module 'planet.logging'
from '/usr/local/lib/python2.4/site-packages/planet/logging/__init__.py'>
The contents of /usr/local/lib/python2.4/site-packages/planet
jkugler@europa:~/www$ ls -la /usr/local/lib/python2.4/site-packages/planet/
total 270
drwxr-sr-x 4 root staff 1024 2007-05-22 16:59 .
drwxrwsr-x 4 root staff 1024 2007-05-22 15:18 ..
-rw-r--r-- 1 root staff 4315 2006-07-26 15:53 atomstyler.py
-rw-r--r-- 1 root staff 8887 2006-07-26 15:53 cache.py
-rw-r--r-- 1 root staff 126446 2006-07-26 15:53 feedparser.py
-rw-r--r-- 1 root staff 58705 2006-07-26 15:53 htmltmpl.py
-rw-r--r-- 1 root staff 38145 2006-07-26 15:53 __init__.py
drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 logging
-rw-r--r-- 1 root staff 13904 2006-07-26 15:53 sanitize.py
drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 tests
-rw-r--r-- 1 root staff 12681 2006-07-26 15:53 timeoutsocket.py

planet.py is simply executing:

import planet
..
..
..
# Activate logging
planet.logging.basicConfig()


I've checked permissions, I've checked import statements, everything I know
to check. Is there something terribly simple I'm missing?

Thanks!

j
 
P

Paul Moore

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.
 
S

Steve Holden

Joshua said:
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'

But, from interactive session:

jkugler@europa:~/www$ ls -l # to show that the modules are not in the
current dir
total 20
-rw-r--r-- 1 jkugler jkugler 2247 2007-05-22 15:26 atom.xml.tmpl
-rw-r--r-- 1 jkugler jkugler 2089 2007-05-22 15:25 index.html.tmpl
-rw-r--r-- 1 jkugler jkugler 564 2007-05-22 15:43 planet.ini
-rw-r--r-- 1 jkugler jkugler 1128 2007-05-22 15:26 rss10.xml.tmpl
-rw-r--r-- 1 jkugler jkugler 838 2007-05-22 15:26 rss20.xml.tmpl
jkugler@europa:~/www$ python
Python 2.4.3 (#2, Oct 6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.<module 'planet.logging'
from '/usr/local/lib/python2.4/site-packages/planet/logging/__init__.py'>
The contents of /usr/local/lib/python2.4/site-packages/planet
jkugler@europa:~/www$ ls -la /usr/local/lib/python2.4/site-packages/planet/
total 270
drwxr-sr-x 4 root staff 1024 2007-05-22 16:59 .
drwxrwsr-x 4 root staff 1024 2007-05-22 15:18 ..
-rw-r--r-- 1 root staff 4315 2006-07-26 15:53 atomstyler.py
-rw-r--r-- 1 root staff 8887 2006-07-26 15:53 cache.py
-rw-r--r-- 1 root staff 126446 2006-07-26 15:53 feedparser.py
-rw-r--r-- 1 root staff 58705 2006-07-26 15:53 htmltmpl.py
-rw-r--r-- 1 root staff 38145 2006-07-26 15:53 __init__.py
drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 logging
-rw-r--r-- 1 root staff 13904 2006-07-26 15:53 sanitize.py
drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 tests
-rw-r--r-- 1 root staff 12681 2006-07-26 15:53 timeoutsocket.py

planet.py is simply executing:

import planet
.
.
.
# Activate logging
planet.logging.basicConfig()


I've checked permissions, I've checked import statements, everything I know
to check. Is there something terribly simple I'm missing?

Thanks!

j
The directory containing the script you are executing is also added to
sys.path. Since you are executing a script called planet ...

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
 
J

Joshua J. Kugler

The directory containing the script you are executing is also added to
sys.path. Since you are executing a script called planet ...

Ah! That's it. That had never occurred to me, as I was under the impression
that your current *working* directory was added to sys.path, not the
directory of the script.

Thanks!

j
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top