473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Module imports fine from interactive, not from script

Yes, I've read this:
http://mail.python.org/pipermail/pyt...st/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.
>>import planet
planet.logging
<module '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
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

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

May 24 '07 #1
3 1933
On 23 May, 02:20, "Joshua J. Kugler" <jos...@eeinternet.comwrote:
Yes, I've read this:http://mail.python.org/pipermail/pyt...st/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.

May 24 '07 #2
Joshua J. Kugler wrote:
Yes, I've read this:
http://mail.python.org/pipermail/pyt...st/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.
>>>import planet
planet.logging
<module '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
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 ----------------

May 24 '07 #3
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

May 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ncf | last post by:
I have a feeling that this is highly unlikely, but does anyone in here know if it's possible to directly call a module, or will I have to wrap it up in a class? i.e., import MyMod...
2
by: jimmyfishbean | last post by:
Hi, I have created a VB.Net windows service. Everything was working fine until I attempted to add a setup project. Now, for some strange, when I try and run the application (using INSTALLUTIL...
9
by: noamsml | last post by:
Hi, I am new to python and am currently writing my first application. One of the problems I quickly ran into, however, is that python's imports are very different from php/C++ includes in the...
6
by: Samuel | last post by:
Hi, Given the following directory structure: --------- |-- Obj.py |-- __init__.py |-- foo | |-- FooTest.py | `-- __init__.py
4
by: rshepard | last post by:
I'm stymied by what should be a simple Python task: accessing the value of a variable assigned in one module from within a second module. I wonder if someone here can help clarify my thinking. I've...
5
by: dg.google.groups | last post by:
Hi all, Is there any standard way to tell if the user is running from a module or from an interactive shell like IDLE or IPython? The best I've come up with so far is for a function to look at...
4
by: rkmr.em | last post by:
Hi I have a function data, that I need to import from a file data, in the directory data If I do this from python interactive shell (linux fedora core 8) from dir /home/mark it works fine: ...
0
by: rkmr.em | last post by:
there was a mistake in my prev mail.. it is not able to successfully import the module. abcde is in directory /home/mark/work/proj1, but it is looking for it in /home/mark from where i am...
0
by: Fredrik Lundh | last post by:
mercado mercado wrote: if you already have two different versions of the script, what stops you from making changes to them? cannot you just insert the appropriate directory in sys.path...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.