Python2.3 absolute import error

M

Markus Doering

Hello,

I just switched from 2.2 to Python 2.3.
I am developing an XML/CGI interface to databases as a python package called
"unitWrapper" containing several modules which ran fine under v2.2.

Running Python2.3 under windows2000 I get import errors when a module
imports another module of the same package with absolute package-names like
this:


main script:
"unitWrapper.wrapper" :
# import error messages and error logging mechanism
from unitWrapper.errorclasses import *

'import site' failed; use -v for traceback
Traceback (most recent call last):
File "wrapper.py", line 67, in ?
from unitWrapper.errorclasses import *
ImportError: No module named unitWrapper.errorclasses



The module exists and curiosly the import above works fine when executed
from outside the package directory. But as soon as there is an import
statement in the imported module unitWrapper.errorclasses, trying to import
other modules in an absolute way, I get the same error again.

I checked the sys.path environment and suprisingly I found that the
site-packages directory is not included when scripts are executed from a
subfolder of site-packages:

sys.path when executing unitWrapper.wrapper.py from site-packages directoy:
['C:\\Python23\\Lib\\site-packages\\unitWrapper',
'C:\\WINNT\\System32\\python23.zip', '', 'C:\\Python23\\DLLs',
'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win',
'C:\\Python23\\lib\\lib-tk', 'C:\\Python23']

sys.path when executing unitWrapper.wrapper.py from outside site-packages
directoy:
['C:\\Documents and Settings\\m.doering\\Desktop',
'C:\\WINNT\\System32\\python23.zip', 'C:\\Documents and
Settings\\m.doering\\Desktop', 'C:\\Python23\\DLLs', 'C:\\Python23\\lib',
'C:\\Python23\\lib\\plat-win', 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23',
'C:\\Python23\\lib\\site-packages']


Is this intended ? Has there changed anything according to relative /
absolute adressing of modules ?

How should modules import other modules of the same package? Are only
relative package-names allowed?

And how do I adress a "parental" module from a subpackage in a relative way?



Any help greatly appreciated,
Markus Doering
--
Markus Döring
Botanic Garden and Botanical Museum Berlin Dahlem,
Dept. of Biodiversit y Informatics
Königin-Luise-Str. 6-8, D-14191 Berlin
Email: (e-mail address removed)
http://www.bgbm.org/BioDivInf/
 
A

A.M. Kuchling

'import site' failed; use -v for traceback
^^^^ what's this?

I expect the installation is incorrect or sys.path is messed up in some way,
and suspect that your import problems are only a side effect, not the root
cause of the problem. Run "python -v" to see the traceback from site.py.

--amk
 
M

Markus Doering

Oh man.
After diving into the site.py traceback I noticed that I had a module named
"types" in my package and site.py tried to import the standard types module
but ended up importing my custom module instead (the scripts directory is
the first in sys.path).
I renamed it and everything seems to work fine.

Thanks,
Markus
 

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,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top