[IronPython] Add reference to .dll located in above directory

Dino Viehland dinov at microsoft.com
Thu May 20 19:38:39 CEST 2010


Instead of sys.path.append('root') can you append the full path to sys.path?

That seems to work for me, I have:

Directory of F:\Product\1\Dlr\x

05/20/2010  10:34 AM    <DIR>          .
05/20/2010  10:34 AM    <DIR>          ..
05/20/2010  10:30 AM    <DIR>          module
05/20/2010  10:30 AM                64 PythonModules.cs
05/20/2010  10:34 AM             3,072 PythonModules.dll
               2 File(s)          3,136 bytes

 Directory of F:\Product\1\Dlr\x\module

05/20/2010  10:30 AM    <DIR>          .
05/20/2010  10:30 AM    <DIR>          ..
05/20/2010  10:36 AM                97 foo.py
               1 File(s)             97 bytes

Foo.py contains:

import clr
import sys
sys.path.append(r'F:\Product\1\Dlr\x')
clr.AddReference('PythonModules')

and both of these work:

10:37:08.72
F:\Product\1\Dlr > ipy x\module\foo.py

10:37:48.96
F:\Product\1\Dlr > cd x

10:37:50.11
F:\Product\1\Dlr\x > ipy module\foo.py

Also you could calculate the path using __file__ from foo.py.


> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of cenovsky at bakalari.cz
> Sent: Thursday, May 20, 2010 12:37 AM
> To: Discussion of IronPython
> Subject: [IronPython] Add reference to .dll located in above directory
> 
> Hi all,
> I have the following directory structure:
> 
> root
> |-- PythonModules.dll
> |-- module
>       |-- foo.py
> 
> I want to add reference to PythonModules.dll  from foo.py. I have the
> compiled Python libraries there I need to use in foo.py.
> 
> I have not successfully make this work with sys.path:
> 
> import clr
> import sys
> sys.path.append('root')      # this is full path to root
> clr.AddReference('PythonModules')
> 
> Traceback (most recent call last):
>    File "C:\test\modul\t.py", line 4, in <module>
> IOError: System.IO.IOException: Could not add reference to assembly
> PythonModules
>     at
> Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[]
> args, Boolean& shouldOptimize)
>     at
> IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`2.Call1(CallSit
> e site, CodeContext context, TFuncType func, T0
> arg0)
>     at
> System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site,
> T0 arg0, T1 arg1, T2 arg2)
>     at __main__$1.__main__(FunctionCode $functionCode) in
> C:\test\modul\t.py:line 14
>     at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
>     at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
>     at IronPython.Hosting.PythonCommandLine.RunFileWorker(String fileName)
>     at IronPython.Hosting.PythonCommandLine.RunFile(String fileName)>>>
> 
> I get the same error when I use clr.AddReferenceToFile('PythonModules.dll').
> 
> The only way how could I make this work is the following:
> 
> import clr
> import sys
> clr.AddReferenceToFileAndPath('..\\PythonModules')
> 
> This is not suitable for me as I want to run foo.py from different
> directories.
> 
> Is it a bug? Or do I something wrong?
> 
> --
> -- Lukáš
> 
> _______________________________________________
> 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