Re: Module imports fine from interactive, not from script

2007-05-24 Thread Joshua J. Kugler
On Thursday 24 May 2007 08:32, Steve Holden wrote:
> 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

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Module imports fine from interactive, not from script

2007-05-24 Thread Steve Holden
Joshua J. Kugler 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  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:
> 
> [EMAIL PROTECTED]:~/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
> [EMAIL PROTECTED]:~/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.
 import planet
 planet.logging
>  from '/usr/local/lib/python2.4/site-packages/planet/logging/__init__.py'>
 planet.logging.basicConfig()

> 
> The contents of /usr/local/lib/python2.4/site-packages/planet
> [EMAIL PROTECTED]:~/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.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module imports fine from interactive, not from script

2007-05-24 Thread Paul Moore
On 23 May, 02:20, "Joshua J. Kugler" <[EMAIL PROTECTED]> 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  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.

-- 
http://mail.python.org/mailman/listinfo/python-list


Module imports fine from interactive, not from script

2007-05-24 Thread 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  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:

[EMAIL PROTECTED]:~/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
[EMAIL PROTECTED]:~/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.
>>> import planet
>>> planet.logging

>>> planet.logging.basicConfig()
>>>

The contents of /usr/local/lib/python2.4/site-packages/planet
[EMAIL PROTECTED]:~/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

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list