Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#5 module cannot be imported from package

closed-fixed
nobody
None
5
2001-06-09
2001-03-13
David R. Handy
No

You can do this:

D:\TestDev\CXX>python
ActivePython 2.0, build 202 (ActiveState Tool Corp.)
based on Python 2.0 (#8, Oct 19 2000, 11:30:05) [MSC
32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more
information.
>>> import sys
>>> sys.path = ['./pyds20'] + sys.path
>>> import example
range object created 007F5090
range object destroyed 007F5090
>>>

But you can't do this:

D:\TestDev\CXX>touch pyds20\__init__.py

D:\TestDev\CXX>python
ActivePython 2.0, build 202 (ActiveState Tool Corp.)
based on Python 2.0 (#8, Oct 19 2000, 11:30:05) [MSC
32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more
information.
>>> import pyds20
>>> import pyds20.example

abnormal program termination

D:\TestDev\CXX>

I traced this a bit using the Visual C++ debugger and
found that initexample() is being called recursively
when you import example.pyd from a package, but not
when you import it directly. I don't think a module
init function is ever meant to be called recursively.
:)

Discussion

  • David R. Handy
    David R. Handy
    2001-03-13

    • summary: Example cannot be imported from package --> module cannot be imported from package
     
  • David R. Handy
    David R. Handy
    2001-03-13

    Logged In: YES
    user_id=171902

    I traced some more to find out why the module init function
    is being called recursively during import. It turns out
    that this happens because the ExtensionModuleBase::module
    (void) function in cxx_extensions.cxx is implemented to get
    a module pointer to itself by reloading itself by name.
    module() is called all over the place, causing lots of
    bogus module reloads. These all happen to succeed in the
    cause of a simple import of "example", but fail
    for "pyds20.example" because "pyds20.example" is a defined
    module but "example" is not. So PyImport_ImportModule
    returns a NULL pointer and everything goes downhill from
    there.

    Is the developer of this code reading these bug reports? It
    would be easier for him to fix this problem than for me.
    Perhaps we could implement ExtensionModuleBase::module
    (void) so that it can create a Module object from the this
    pointer without doing a full module reload using
    PyImport_ImportModule(). My attempt to do this didn't work,
    but someone who knows this code may be able to do it
    correctly.

     
  • Greg Landrum
    Greg Landrum
    2001-05-05

    Logged In: YES
    user_id=9335

    I've experienced the same bug, but I tracked it back to
    a different problem.

    I have a fix which appears to work pretty well. I'd be
    happy to send it to the powers-that-be, if they give me
    some pointers on how to do so.

    -greg

     
    • status: open --> closed-fixed
     
  • Logged In: YES
    user_id=28665

    Fixed for 5.1 with Greg Landrum's solution

     
  • Logged In: YES
    user_id=28665

    Fixed for 5.1 with Greg Landrum's solution