[New-bugs-announce] [issue15828] imp.load_module doesn't support C_EXTENSION type

Mark Tolonen report at bugs.python.org
Fri Aug 31 09:32:28 CEST 2012

New submission from Mark Tolonen:

I built a C extension using SWIG for both Python 3.2 and Python 3.3.  The Python file supplying class proxies uses imp.load_module and fails with the following traceback on 3.3.0rc1, but works on 3.2.3:

   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File ".\Widget.py", line 26, in <module>
       _Widget = swig_import_helper()
     File ".\Widget.py", line 22, in swig_import_helper
       _mod = imp.load_module('_Widget', fp, pathname, description)
     File "D:\dev\python33\lib\imp.py", line 171, in load_module
       raise ImportError(msg, name=name)
   ImportError: Don't know how to import _Widget (type code 3

It looks like imp.py is new in Python 3.3, and imp.load_module no longer supports the C_EXTENSION type.  It looks like a regression.

To reproduce, I was able to run the following lines with the .pyd file in the current directory:

   import imp
   fp, pathname, description = imp.find_module('_Widget')
   imp.load_module('_Widget', fp, pathname, description)

Nit: Also note the missing final ')' in the ImportError message.

components: Library (Lib)
messages: 169506
nosy: metolone
priority: normal
severity: normal
status: open
title: imp.load_module doesn't support C_EXTENSION type
type: behavior
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list