[IronPython] Program.py can't find its DLL when compiled with pyc.py

Dave Wald davew252 at tx.rr.com
Tue Jun 14 04:56:53 CEST 2011

On 6/13/2011 7:13 PM, Brian Wilson wrote:
> Can anyone shed any light on this? I spent several hours searching the
> Web for some hints with no luck.
> Using VS2010, I built a little IronPython program and added a Windows
> form to it as a separate project.
> It all works fine when invoked as "ipyw.exe -D Program.py".
> (IronPython 2.6.2 with .net 2.0)
> Moving on to try out pyc.py, I built a trivial program (no separate
> form) and the executable works fine.
> (I used the sample that gets created when you create a new IP project
> in VS2010.)
> But when I try to build and run my version with the separate form, it
> does not work; my compiled python can't find the DLL when run.
> The exact error message is this:
> Unhandled Exception: System.IO.IOException: Could not add reference to
> assembly form.dll
>     at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[]
> args, Boolean&  shouldOptimize)
>     at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`6.Call5(CallSite
> site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2,
> T3 arg3, T4 arg4)
>     at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite
> site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
>     at IronPython.Runtime.Importer.Import(CodeContext context, String
> fullName, PythonTuple from, Int32 level)
>     at IronPython.Runtime.Operations.PythonOps.InitializeModule(Assembly
> precompiled, String main, String[] references)
>     at PythonMain.Main()
> The pyc.py build command is
>    ipy.exe pyc.py /main:Program.py /out:setup /target:winexe
> I am building and running in a directory containing the DLL's,
> form.dll
> IronPython.Modules.dll
> IronPython.dll
> Lib
> Microsoft.Dynamic.dll
> Microsoft.Scripting.Core.dll
> Microsoft.Scripting.ExtensionAttribute.dll
> Microsoft.Scripting.dll
> Program.py
> pyc.py
> Here is my Program.py
> import clr
> clr.AddReference('System.Windows.Forms')
> from System.Windows.Forms import *
> clr.AddReference('form.dll')
> from ipform import Form1
> form = Form1()
> Application.Run(form)
I haven't tried the pyc tool yet, (haven't needed to), but I have run 
into similar problems just running under IPy and VS.
I suspect pyc'ing is a whole different set of issues.
But anyway, I have taken to always using the 
clr.AddReferenceToFileAndPath(...) form for my extraneous dll's for that 
I add a bin folder to my project and put all my dlls in it and then 
reference them by filepath, e.g.:
I think the  "clr.AddReference(...)" form is really only for well-known 
.Net dlls.
It's spelled out pretty well here:

Give that a try.


More information about the Ironpython-users mailing list