[IronPython] [python] Re: Embedding CPython Messes with the IronPython 2 Import Mechanism

Michael Foord fuzzyman at voidspace.org.uk
Fri Nov 2 23:33:09 CET 2007


You asked for it. :-)

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
Unable to cast object of type 'System.Reflection.Module' to type 
'System.Reflect
ion.Emit.ModuleBuilder'.
   at System.Reflection.Emit.AssemblyBuilderData.GetInMemoryAssemblyModule()
   at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, 
Assembly
BuilderAccess access, String dir, Evidence evidence, PermissionSet 
requiredPermi
ssions, PermissionSet optionalPermissions, PermissionSet 
refusedPermissions, Sta
ckCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes)
   at System.AppDomain.DefineDynamicAssembly(AssemblyName name, 
AssemblyBuilderA
ccess access)
   at Microsoft.Scripting.Generation.AssemblyGen..ctor(String 
moduleName, String
 outDir, String outFile, AssemblyGenAttributes generationAttributes, 
PortableExe
cutableKinds peKind, ImageFileMachine machine)
   at 
Microsoft.Scripting.Generation.StaticFieldModuleGenerator.CreateModuleAsse
mbly(ScriptCode scriptCode)
   at 
Microsoft.Scripting.Generation.StaticFieldModuleGenerator.CreateSlotFactor
y(ScriptCode scriptCode)
   at 
Microsoft.Scripting.Generation.OptimizedModuleGenerator.CreateStorageAlloc
ator(ScriptCode scriptCode)
   at 
Microsoft.Scripting.Generation.OptimizedModuleGenerator.GenerateScriptMeth
ods()
   at 
Microsoft.Scripting.Generation.OptimizedModuleGenerator.GenerateScope()
   at Microsoft.Scripting.ScriptDomainManager.CreateModule(String name, 
ScriptMo
duleKind kind, Scope scope, ScriptCode[] scriptCodes)
   at Microsoft.Scripting.ScriptDomainManager.CompileModule(String name, 
ScriptM
oduleKind kind, Scope scope, CompilerOptions options, ErrorSink 
errorSink, Sourc
eUnit[] sourceUnits)
   at Microsoft.Scripting.ScriptDomainManager.CompileModule(String name, 
SourceU
nit sourceUnit)
   at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext 
context, Stri
ng name, String path)
   at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, 
String nam
e, String fullName, List path)
   at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, 
String
name)
   at IronPython.Runtime.Importer.ImportModule(CodeContext context, 
String modNa
me, Boolean bottom)
   at IronPython.Runtime.Builtin.__import__(CodeContext context, String 
name, Ob
ject globals, Object locals, Object fromList)
   at _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String 
, IAttr
ibutesCollection , IAttributesCollection , PythonTuple )
   at Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext 
context, T0 a
rg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext 
context, Str
ing fullName)
   at ##18(Object[] , CodeContext )
   at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, 
Boolean tryEva
luate)
   at Microsoft.Scripting.ScriptCode.Run(ScriptModule module)
   at Microsoft.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule 
module)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(String 
code, IScri
ptModule module)
   at Microsoft.Scripting.Shell.CommandLine.RunOneInteraction()
   at Microsoft.Scripting.Shell.CommandLine.TryInteractiveAction()
   at IronPython.Hosting.PythonCommandLine.TryInteractiveAction()
   at Microsoft.Scripting.Shell.CommandLine.RunInteractiveLoop()
TypeError: Unable to cast object of type 'System.Reflection.Module' to 
type 'Sys
tem.Reflection.Emit.ModuleBuilder'.

 >>>


Dino Viehland wrote:
> Could you run with -X:ExceptionDetail and report back the stack trace?  That'll let us know where the exception is actually coming from.
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
> Sent: Friday, November 02, 2007 3:25 PM
> To: Discussion of IronPython
> Subject: [IronPython] Embedding CPython Messes with the IronPython 2 Import Mechanism
>
> 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
>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   




More information about the Ironpython-users mailing list