Thank you, Bradley. I found a simple sample code on the maillist. Now I could load and execute a pure python function in a py file in C#.
And a new problem is that the PythonEngine.ImportModule("modulename") method always return NULL in my case. The modulename.py comsumes a third part ctypes wrapped library (the Rtree 0.7 python library). It seems the PythonEngine can not find it, but actually it has been installed to the default path (C:\Python262\Lib\site-packages\rtree) , and the modulename.py file runs smoothly under python command line. I worte a new py file which only contains a function returning the sys.path, and load it in C#, the sys.path seems OK. So I don't know what's wrong.... Thanks. Zhiyu Li 2013-03-29 lizy10b 发件人: Bradley Friedman 发送时间: 2013-03-28 22:15:18 收件人: lizy10b 抄送: pythondotnet 主题: Re: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code What you are looking to do is "embed" a python interpreter in your .net project, using pythonnet, and then tell the runtime to execute your python script. I have done this in one of my projects. It does work. http://pythonnet.sourceforge.net/readme.html#embedding Sent from my iPad On Mar 28, 2013, at 8:31 AM, "lizy10b" <lizy...@126.com> wrote: Hi there, I am a freshman and new to python.net. I have a *.py script which calls a third part python library, and the library is a ctypes python wrapper of a C++ dll (or say C-based python extension?). Frist I tried to make it using IronPython. IronPython works well when I load a pure python *.py (no third part libraries) file and execute it in C# code. But it failed when I load a *.py which comsumes a thrid part ctypes python wrapper library mentioned above. Then I turn to python.net. But I don't know how to load and execute *.py in C# code using python.net. Thanks. Zhiyu Li Student China 2013-03-28 lizy10b _________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet