getting started - can't import a simple dll
I'm evaluating PDN for use in an upcoming project. 1. installed Python 2.6.5 2. installed PDN - copied the clr.pyd file to Python's DLLs folder, and copied Python.Runtime.dll to Python's root 3. copy my dll (VS2010, simple C# class lib with two methods) into Python's root. 4. start python (using the python.exe from 2.6.5, not the one from PDN)
import clr clr.AddReference("My.DLL") Traceback (most recent call last): File "<stdin>", line 1, in <module> System.IO.FileNotFoundException: Unable to find assembly 'HFF.Helper.Utilities'.
at Python.Runtime.CLRModule.AddReference(String name)
I assume I'm making some incredibly obvious newbie error. Can anyone point me in the right direction? And, where can I find good docs/reference/discussion on using PDN? thanks - Jason
Thanks. I tried creating a test assembly with just a default constructor and no other dependencies, and I get the same error when I try to import it. I also tried setting the path variable, through windows as well as in code, and get the same result. Assuming my dll is named "TestLib.dll", I should be able to do clr.AddReference("TestLib"), correct? Do I have to strong name my assemblies, or put them in the GAC? Or is that optional? Any other suggestions of how to track this down? On Tue, Dec 14, 2010 at 7:21 PM, Laszlo Sebo < laszlo.sebo@primefocusworld.com> wrote:
It appears that some reference dependencies of the My.DLL assembly (the assembly containing HFF.Helper.Utilities ?) weren't found.
Make sure that whichever referenced assembly has those classes is accessible through the path env variables. If needed, you can add it inside python, by simply doing something like:
import sys sys.path.append('place where my dlls are')
This is probably the best documentation out there: http://pythonnet.sourceforge.net/readme.html
But once you get the initial assemblies to work, its fairly straightforward since you just use the .net classes natively from python.
cheers, laszlo
On 14/12/2010 4:53 PM, Jason Awbrey wrote:
I'm evaluating PDN for use in an upcoming project.
1. installed Python 2.6.5 2. installed PDN - copied the clr.pyd file to Python's DLLs folder, and copied Python.Runtime.dll to Python's root 3. copy my dll (VS2010, simple C# class lib with two methods) into Python's root. 4. start python (using the python.exe from 2.6.5, not the one from PDN)
import clr clr.AddReference("My.DLL") Traceback (most recent call last): File "<stdin>", line 1, in <module> System.IO.FileNotFoundException: Unable to find assembly 'HFF.Helper.Utilities'.
at Python.Runtime.CLRModule.AddReference(String name)
I assume I'm making some incredibly obvious newbie error. Can anyone point me in the right direction?
And, where can I find good docs/reference/discussion on using PDN?
thanks - Jason
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
When you import the assembly it will be referenced by the assembly name defined in the project settings (which is what the dll will be named as). GAC isn't required ( i never do that ). I just did a quick test here. Made an empty Class project via Visual Studio 2008. Then tweaked the source to add 2 functions: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ClassLibrary1 { public class Class1 { public string Function1() { return "Test Function Called"; } public void Function2() { Console.WriteLine("Hello World"); } } } I built it with all default settings (as a class library), then copied the dll to the python / lib / site-packages folder, along with the clr.pyd, Python.Runtime.dll and Python.Runtime.dll.config files Then from python: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel win32 Type "help", "copyright", "credits" or "license" for more information.
import clr clr.AddReference('ClassLibrary1') <System.Reflection.Assembly object at 0x01DF5580> import ClassLibrary1 myObject = ClassLibrary1.Class1() myObject.Function1() u'Test Function Called' myObject.Function2() Hello World
Note that the "import ClassLibrary1" is the namespace not the assembly (it just happens to be the same since its all default values). I wonder if your issue is somehow related to VS2010? Could it be adding some default references? What references are listed in VS? cheers, laszlo On 14/12/2010 5:47 PM, Jason Awbrey wrote:
Thanks. I tried creating a test assembly with just a default constructor and no other dependencies, and I get the same error when I try to import it.
I also tried setting the path variable, through windows as well as in code, and get the same result.
Assuming my dll is named "TestLib.dll", I should be able to do clr.AddReference("TestLib"), correct?
Do I have to strong name my assemblies, or put them in the GAC? Or is that optional?
Any other suggestions of how to track this down?
I recompiled using .NET 2.0 and now I can load the DLL. Is there any support for frameworks after 2.0? I'd hate to lose the ability to use LINQ. Also, you mentioned Python.Runtime.dll.config. I don't have this file. What's in it? thanks for your help On Tue, Dec 14, 2010 at 8:06 PM, Laszlo Sebo < laszlo.sebo@primefocusworld.com> wrote:
When you import the assembly it will be referenced by the assembly name defined in the project settings (which is what the dll will be named as). GAC isn't required ( i never do that ).
I just did a quick test here. Made an empty Class project via Visual Studio 2008.
Then tweaked the source to add 2 functions:
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ClassLibrary1 { public class Class1 { public string Function1() { return "Test Function Called"; } public void Function2() { Console.WriteLine("Hello World"); } } }
I built it with all default settings (as a class library), then copied the dll to the python / lib / site-packages folder, along with the clr.pyd, Python.Runtime.dll and Python.Runtime.dll.config files
Then from python:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel win32 Type "help", "copyright", "credits" or "license" for more information.
import clr clr.AddReference('ClassLibrary1') <System.Reflection.Assembly object at 0x01DF5580> import ClassLibrary1 myObject = ClassLibrary1.Class1() myObject.Function1() u'Test Function Called' myObject.Function2() Hello World
Note that the "import ClassLibrary1" is the namespace not the assembly (it just happens to be the same since its all default values). I wonder if your issue is somehow related to VS2010? Could it be adding some default references? What references are listed in VS?
cheers, laszlo
On 14/12/2010 5:47 PM, Jason Awbrey wrote:
Thanks. I tried creating a test assembly with just a default constructor and no other dependencies, and I get the same error when I try to import it.
I also tried setting the path variable, through windows as well as in code, and get the same result.
Assuming my dll is named "TestLib.dll", I should be able to do clr.AddReference("TestLib"), correct?
Do I have to strong name my assemblies, or put them in the GAC? Or is that optional?
Any other suggestions of how to track this down?
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
Yeah you don't actually need the .config file, it's just a dll mapping file for use with mono on linux (i've been in linux land for a while, so it must have popped from my subconcious). I believe currently clr 2.x is supported, which means that up to .net 3.5 it should work fine, as those releases still use the 2.0 runtime (someone correct me if i'm wrong). LINQ was added with 3.5, so it should work. cheers, laszlo I recompiled using .NET 2.0 and now I can load the DLL. Is there any support for frameworks after 2.0? I'd hate to lose the ability to use LINQ. Also, you mentioned Python.Runtime.dll.config. I don't have this file. What's in it?
Laszlo Sebo <laszlo.sebo@...> writes:
I believe currently clr 2.x is supported, which means that up to .net 3.5 it should work fine, as those releases still use the 2.0 runtime (someone correct me if i'm wrong). LINQ was added with 3.5, so it should work. cheers, laszlo I recompiled using .NET 2.0 and now I can load the DLL. Is there any support for frameworks after 2.0? I'd hate to lose the ability to use LINQ.Also, you mentioned Python.Runtime.dll.config. I don't have this file. What's in it?
I managed to compile Python.NET for .NET 4 with only a couple of minor modifications to the code: http://thread.gmane.org/gmane.comp.python.dotnet/969 NB: I put both clr.pyd and Python.Runtime.dll in my python root dir (C:\Python26) HTH, Dave
I am trying to raise finance to setup and develop a multi-lingual pythondotnet site to promote Pythondotnet globally in London. Pythondotnet is hardly known, taught, used in this part of the world. Certainly, it is true in China. To start with, I would like get a team going to do a English and Chinese site. Can anyone suggest the way forward? I am sure that I will need financial support to start with. Regards. David Shi
participants (4)
-
Dave Hirschfeld
-
David Shi
-
Jason Awbrey
-
Laszlo Sebo