[IronPython] Embedding CPython Messes with the IronPython 2 Import Mechanism

Michael Foord fuzzyman at voidspace.org.uk
Fri Nov 2 23:25:26 CET 2007


Hello Guys,

Not sure what is going on here, nor whether it indicates a bug in 
IronPython, but it is certainly odd. Loading a CPython interpreter 
through the Python.NET assembly seems to change the IronPython (2a5) 
import machinery.

I have a test module 'xyzz.py' that has an unused name 'wibble'. 
Unsurprisingly, attempting to import this into IronPython 2.0a5 raises a 
name error:

IronPython console: IronPython 2.0A5 (2.0.11011.00) on .NET 2.0.50727.1378
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> import xyzz
Traceback (most recent call last):
  File , line 0, in ##7
  File , line 0, in _stub_##2
  File C:\compile\cext\trunk\cext\xyzz.py, line 1, in Initialize
NameError: name 'wibble' is not defined


Executing the following code, (using the 'Python.Runtime' assembly from 
Python.NET with Python 2.4):

IronPython console: IronPython 2.0A5 (2.0.11011.00) on .NET 2.0.50727.1378
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> import clr
 >>> clr.AddReference('Python.Runtime')
 >>>
 >>> from Python.Runtime import PythonEngine
 >>> engine = PythonEngine()
 >>> engine.Initialize()
 >>>
 >>> import xyzz
Traceback (most recent call last):
  File , line 0, in ##18
  File , line 0, in _stub_##2
  File mscorlib, line unknown, in DefineDynamicAssembly
  File mscorlib, line unknown, in InternalDefineDynamicAssembly
TypeError: Unable to cast object of type 'System.Reflection.Module' to 
type 'Sys
tem.Reflection.Emit.ModuleBuilder'.

Just importing the 'PythonEngine' isn't enough. The problem only happens 
if the PythonEngine is instantiated and initialized.

All the best,


Michael





More information about the Ironpython-users mailing list