Python2.3 absolute import error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus Doering

    Python2.3 absolute import error

    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
    "unitWrappe r" 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.wr apper" :[color=blue]
    >
    ># import error messages and error logging mechanism
    >from unitWrapper.err orclasses import *
    >[/color]

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



    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.err orclasses, 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.wra pper.py from site-packages directoy:
    ['C:\\Python23\\ Lib\\site-packages\\unitW rapper',
    'C:\\WINNT\\Sys tem32\\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.wra pper.py from outside site-packages
    directoy:
    ['C:\\Documents and Settings\\m.doe ring\\Desktop',
    'C:\\WINNT\\Sys tem32\\python23 .zip', 'C:\\Documents and
    Settings\\m.doe ring\\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: m.doering@bgbm. org



  • A.M. Kuchling

    #2
    Re: Python2.3 absolute import error

    On Mon, 25 Aug 2003 17:56:52 +0200,[color=blue]
    > 'import site' failed; use -v for traceback[/color]
    ^^^^ 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

    Comment

    • Markus Doering

      #3
      Re: Python2.3 absolute import error

      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

      "A.M. Kuchling" <amk@amk.ca> wrote in message
      news:g8KcnaISvK GppdeiRTvUqg@sp eakeasy.net...[color=blue]
      > On Mon, 25 Aug 2003 17:56:52 +0200,[color=green]
      > > 'import site' failed; use -v for traceback[/color]
      > ^^^^ what's this?
      >
      > I expect the installation is incorrect or sys.path is messed up in some[/color]
      way,[color=blue]
      > 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[/color]


      Comment

      Working...