From nicole.haenni at gmail.com Mon Mar 4 01:10:35 2013 From: nicole.haenni at gmail.com (Nicole Haenni) Date: Mon, 4 Mar 2013 01:10:35 +0100 Subject: [Python.NET] Survey for framework and library developers: "Information needs in software ecosystems" In-Reply-To: References: Message-ID: Hi, I?m Nicole Haenni and I'm doing research for my thesis at the University of Berne (scg.unibe.ch) with Mircea Lungu and Niko Schwarz. We are researching on monitoring the activity in software ecosystems. This is a study about information needs that arise in such software ecosystems. I need your help to fill out the survey below. It takes about 10 minutes to complete it. A software ecosystem can be a project repository like GitHub, an open source community (e.g. the Apache community) or a language-based community (e.g. Smalltalk has Squeaksource, Ruby has Rubyforge). We formulate our research question as follows: "What information needs arise when developers use code from other projects, or see their own code used elsewhere." Survey link: http://bit.ly/14Zc71N or original link: https://docs.google.com/spreadsheet/viewform?formkey=dFBJUmVodVU1V3BMMGRPRWxBdjdDbVE6MA Thank you for your support! Nicole Haenni ----------------------------------------- Software Composition Group Institut f?r Informatik Universit?t Bern Neubr?ckstrasse 10 CH-3012 Bern SWITZERLAND -------------- next part -------------- An HTML attachment was scrubbed... URL: From acampbell at ltufz.com Wed Mar 20 17:16:50 2013 From: acampbell at ltufz.com (Alex Campbell) Date: Wed, 20 Mar 2013 12:16:50 -0400 Subject: [Python.NET] Loading C# DLLs from CPython Message-ID: Hi, We need to access C# managed DLLs from CPython. The obvious choice is IronPython, but this is not easily possible since we can't swap out the interpreter. We saw Pythonnet, and from the description it seemed that it would provide a package for accessing C# from Python. Unfortunately, rather than a module, it seems to be just the interpreter (which doesn't avoid the issue of not being able to swap the interpreter out). The only other solution we see is to use nPython or IronPython to make a COM interface, access this COM interface using a python library, and importing that python library into CPython. Does anyone see a less convoluted way of doing this? Thanks, -Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Wed Mar 20 17:34:25 2013 From: tony at pyxll.com (Tony Roberts) Date: Wed, 20 Mar 2013 16:34:25 +0000 Subject: [Python.NET] Loading C# DLLs from CPython In-Reply-To: References: Message-ID: Hi Alex, you can import the clr module in the standard cPython interpreter, so I don't think there's any need to use nPython. You just need to make sure that the clr.pyd module is somewhere on your pythonpath. regards, Tony On Wed, Mar 20, 2013 at 4:16 PM, Alex Campbell wrote: > Hi, > > We need to access C# managed DLLs from CPython. The obvious choice is > IronPython, but this is not easily possible since we can't swap out the > interpreter. We saw Pythonnet, and from the description it seemed that it > would provide a package for accessing C# from Python. > > Unfortunately, rather than a module, it seems to be just the interpreter > (which doesn't avoid the issue of not being able to swap the interpreter > out). > > The only other solution we see is to use nPython or IronPython to make a > COM interface, access this COM interface using a python library, and > importing that python library into CPython. > > Does anyone see a less convoluted way of doing this? > > Thanks, > -Alex > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Wed Mar 20 17:43:10 2013 From: brad at fie.us (brad at fie.us) Date: Wed, 20 Mar 2013 12:43:10 -0400 Subject: [Python.NET] Loading C# DLLs from CPython In-Reply-To: References: Message-ID: <33C8C503-6011-418B-89A7-5B0741C7AF93@fie.us> You are incorrect that it's just an interpreter. That is one thing it can do. But it also acts as a module. For example, I have pythonnet and .net dlls importing into Autodesk Maya, which is a third party product that embeds it's own cPython. It can get a little more complicated if you need multi-platform support because you need to compile it differently for .net versus mono. But it can be used across all three major platforms. -brad On Mar 20, 2013, at 12:16 PM, Alex Campbell wrote: > Hi, > > We need to access C# managed DLLs from CPython. The obvious choice is IronPython, but this is not easily possible since we can't swap out the interpreter. We saw Pythonnet, and from the description it seemed that it would provide a package for accessing C# from Python. > > Unfortunately, rather than a module, it seems to be just the interpreter (which doesn't avoid the issue of not being able to swap the interpreter out). > > The only other solution we see is to use nPython or IronPython to make a COM interface, access this COM interface using a python library, and importing that python library into CPython. > > Does anyone see a less convoluted way of doing this? > > Thanks, > -Alex > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From swpark71 at gmail.com Fri Mar 22 21:44:46 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 22 Mar 2013 13:44:46 -0700 Subject: [Python.NET] How to use Python for .NET? Have a problem to use in Windows 2008 R2 SP1 Message-ID: Hello, I just downloaded pythonnet-2.0-Beta0-clr4.0_140_py27.zip from http://sourceforge.net/projects/pythonnet/, and extract to c:\temp and ran nPython.exe, got below error. Current my test machine has Windows 2008 R2 SP1 with Python 2.7.3 (32bit). When looked the error, and googled it. someone says I need to copy python27.dll into c:\windows\system32. However, I can't find the file. Any idea? Thank you, Spark, C:\temp\pythonnet20>nPython.exe Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'python27': The specified module could not be found . (Exception from HRESULT: 0x8007007E) at Python.Runtime.Runtime.Py_Initialize() at Python.Runtime.Runtime.Initialize() in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonn et\src\runtime\runtime.cs:line 78 at Python.Runtime.PythonConsole.Main(String[] args) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\ trunk\pythonnet\src\console\pythonconsole.cs:line 21 -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Fri Mar 22 21:51:27 2013 From: brad at fie.us (brad at fie.us) Date: Fri, 22 Mar 2013 16:51:27 -0400 Subject: [Python.NET] How to use Python for .NET? Have a problem to use in Windows 2008 R2 SP1 In-Reply-To: References: Message-ID: <5A1B4763-D497-4168-AB35-3757256CD571@fie.us> python27.dll is likely not in your path. So it can't dynamically link to it. There are a lot of ways to remedy that. Adding your python 2.7 install to your path. Or moving the pythonnet binaries into your python 2.7 install. You could also edit the .config file for the pythonnet install to give it an absolute path to the python2.7 on your system. Adding python2.7 to your system directory probably isn't the best idea. If python 2.7 were meant to be installed to the "system" it would install there itself. A long time ago, I used to make it a point to install my python from "activestate" installers rather than the default python installers, because their installer set up the bin and path variables for me and made sure that python was available system wide. -brad On Mar 22, 2013, at 4:44 PM, Seungweon Park wrote: > Hello, > > I just downloaded pythonnet-2.0-Beta0-clr4.0_140_py27.zip from http://sourceforge.net/projects/pythonnet/, and extract to c:\temp and ran nPython.exe, got below error. > > Current my test machine has > Windows 2008 R2 SP1 with Python 2.7.3 (32bit). > > When looked the error, and googled it. someone says I need to copy python27.dll into c:\windows\system32. However, I can't find the file. Any idea? > > Thank you, > Spark, > > C:\temp\pythonnet20>nPython.exe > > Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'python27': The specified module could not be found > . (Exception from HRESULT: 0x8007007E) > at Python.Runtime.Runtime.Py_Initialize() > at Python.Runtime.Runtime.Initialize() in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonn > et\src\runtime\runtime.cs:line 78 > at Python.Runtime.PythonConsole.Main(String[] args) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\ > trunk\pythonnet\src\console\pythonconsole.cs:line 21 > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Fri Mar 22 23:28:27 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 22 Mar 2013 15:28:27 -0700 Subject: [Python.NET] How to compile Python for .Net in VS2010 and .NET 4? Message-ID: Hello, I downloaded from SVN, and tried to compile it in VS2010 with Windows 2008 R2. However, it requires Mono.Unix reference in error message. so I installed mono(mono-2.10.9-gtksharp-2.12.11-win32-0.exe from http://www.go-mono.com/mono-downloads/download.html. And added Mono.Posix.dll as reference, and compiled again, got error. FYI, I selected build option as DebugWin/x86. ------------------------------------------------------------------------------ The command "call "buildclrmodule.bat" x86 "c:\cvs\pythonnet\src\runtime\" "c:\cvs\pythonnet\src\runtime\bin\x86\release\clr.pyd" copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\Python.Runtime.dll" "c:\cvs\pythonnet\" copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\*.pdb" "c:\cvs\pythonnet" copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\clr.pyd" "c:\cvs\pythonnet" " exited with code 1." ------------------------------------------------------------------------------ Any idea? Thanks, spark. [image: Inline image 1] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 44794 bytes Desc: not available URL: From swpark71 at gmail.com Fri Mar 22 23:42:40 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 22 Mar 2013 15:42:40 -0700 Subject: [Python.NET] How to compile Python for .Net in VS2010 and .NET 4? In-Reply-To: References: Message-ID: As I opened the file 'buildclrmodule.bat' it has comment like :: Call with buildclrmodule.bat I added to support x86 below. and compiled successfully. However, when I run nPython.exe C:\CVS\Pythonnet>npython Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named 'PyUnicodeUCS4_FromUnicode' in DLL 'python27'. at Python.Runtime.Runtime.PyUnicode_FromUnicode(String s, Int32 size) at Python.Runtime.Runtime.Initialize() in c:\CVS\Pythonnet\src\runtime\runtime.cs:line 101 at Python.Runtime.PythonEngine.Initialize() in c:\CVS\Pythonnet\src\runtime\pythonengine.cs:line 117 at Python.Runtime.PythonConsole.Main(String[] args) in c:\CVS\Pythonnet\src\console\pythonconsole.cs:line 22 C:\CVS\Pythonnet> What do I need to run without above message? Thank you, Spark. ---------------------------------------------------- @echo off set TARGET_PLATFORM=%1 set INPUT_DIRECTORY=%~2 set INPUT_PATH="%INPUT_DIRECTORY%\clrmodule.il" set OUTPUT_PATH=%3 if %TARGET_PLATFORM%==AnyCPU goto SETUP32 *if %TARGET_PLATFORM%==x86 goto SETUP32* if %TARGET_PLATFORM%==x64 goto SETUP64 goto ERROR_BAD_PLATFORM :SETUP32 set INCLUDE_PATH="%INPUT_DIRECTORY%\x86" goto BUILD_CLR_MODULE :SETUP64 set INCLUDE_PATH="%INPUT_DIRECTORY%\x64" set ILASM_EXTRA_ARGS=/pe64 /x64 goto BUILD_CLR_MODULE :ERROR_BAD_PLATFORM echo Unknown target platform: %TARGET_PLATFORM% exit /b 1 :ERROR_MISSING_INPUT echo Can't find input file: %INPUT_PATH% exit /b 1 :BUILD_CLR_MODULE if not exist %INPUT_PATH% goto ERROR_MISSING_INPUT %windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH% ::: 2.0 or 3.5 :::%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH% -------------------------------------------------------- On Fri, Mar 22, 2013 at 3:28 PM, Seungweon Park wrote: > Hello, > > I downloaded from SVN, and tried to compile it in VS2010 with Windows 2008 > R2. However, it requires Mono.Unix reference in error message. so I > installed mono(mono-2.10.9-gtksharp-2.12.11-win32-0.exe from > http://www.go-mono.com/mono-downloads/download.html. And added > Mono.Posix.dll as reference, and compiled again, got error. FYI, I selected > build option as DebugWin/x86. > > > ------------------------------------------------------------------------------ > The command "call "buildclrmodule.bat" x86 "c:\cvs\pythonnet\src\runtime\" > "c:\cvs\pythonnet\src\runtime\bin\x86\release\clr.pyd" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\Python.Runtime.dll" > "c:\cvs\pythonnet\" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\*.pdb" > "c:\cvs\pythonnet" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\clr.pyd" > "c:\cvs\pythonnet" > " exited with code 1." > > ------------------------------------------------------------------------------ > Any idea? > > Thanks, > spark. > > [image: Inline image 1] > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 44794 bytes Desc: not available URL: From brad at fie.us Sat Mar 23 03:06:22 2013 From: brad at fie.us (brad at fie.us) Date: Fri, 22 Mar 2013 22:06:22 -0400 Subject: [Python.NET] How to compile Python for .Net in VS2010 and .NET 4? In-Reply-To: References: Message-ID: Your python was built with UCS2 unicode support, rather than UCS4. There is a compiler directive in the VS project of pythonnet for that. Pythons that are compiled UCS2 and UCS4 respectively, are binary incompatible with one another. Hence, pythonnet cannot target both at the same time. -brad On Mar 22, 2013, at 6:42 PM, Seungweon Park wrote: > As I opened the file 'buildclrmodule.bat' it has comment like :: Call with buildclrmodule.bat > I added to support x86 below. and compiled successfully. However, when I run nPython.exe > > C:\CVS\Pythonnet>npython > > Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named 'PyUnicodeUCS4_FromUnicode' > in DLL 'python27'. > at Python.Runtime.Runtime.PyUnicode_FromUnicode(String s, Int32 size) > at Python.Runtime.Runtime.Initialize() in c:\CVS\Pythonnet\src\runtime\runtime.cs:line 101 > at Python.Runtime.PythonEngine.Initialize() in c:\CVS\Pythonnet\src\runtime\pythonengine.cs:line 117 > at Python.Runtime.PythonConsole.Main(String[] args) in c:\CVS\Pythonnet\src\console\pythonconsole.cs:line 22 > > C:\CVS\Pythonnet> > > What do I need to run without above message? > > Thank you, > Spark. > > > ---------------------------------------------------- > @echo off > > set TARGET_PLATFORM=%1 > set INPUT_DIRECTORY=%~2 > set INPUT_PATH="%INPUT_DIRECTORY%\clrmodule.il" > set OUTPUT_PATH=%3 > > if %TARGET_PLATFORM%==AnyCPU goto SETUP32 > if %TARGET_PLATFORM%==x86 goto SETUP32 > if %TARGET_PLATFORM%==x64 goto SETUP64 > goto ERROR_BAD_PLATFORM > > :SETUP32 > set INCLUDE_PATH="%INPUT_DIRECTORY%\x86" > goto BUILD_CLR_MODULE > > :SETUP64 > set INCLUDE_PATH="%INPUT_DIRECTORY%\x64" > set ILASM_EXTRA_ARGS=/pe64 /x64 > goto BUILD_CLR_MODULE > > :ERROR_BAD_PLATFORM > echo Unknown target platform: %TARGET_PLATFORM% > exit /b 1 > > :ERROR_MISSING_INPUT > echo Can't find input file: %INPUT_PATH% > exit /b 1 > > :BUILD_CLR_MODULE > if not exist %INPUT_PATH% goto ERROR_MISSING_INPUT > %windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH% > > ::: 2.0 or 3.5 > :::%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH% > -------------------------------------------------------- > > > On Fri, Mar 22, 2013 at 3:28 PM, Seungweon Park wrote: > Hello, > > I downloaded from SVN, and tried to compile it in VS2010 with Windows 2008 R2. However, it requires Mono.Unix reference in error message. so I installed mono(mono-2.10.9-gtksharp-2.12.11-win32-0.exe from http://www.go-mono.com/mono-downloads/download.html. And added Mono.Posix.dll as reference, and compiled again, got error. FYI, I selected build option as DebugWin/x86. > > ------------------------------------------------------------------------------ > The command "call "buildclrmodule.bat" x86 "c:\cvs\pythonnet\src\runtime\" "c:\cvs\pythonnet\src\runtime\bin\x86\release\clr.pyd" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\Python.Runtime.dll" "c:\cvs\pythonnet\" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\*.pdb" "c:\cvs\pythonnet" > copy "c:\cvs\pythonnet\src\runtime\bin\x86\Release\clr.pyd" "c:\cvs\pythonnet" > " exited with code 1." > ------------------------------------------------------------------------------ > Any idea? > > Thanks, > spark. > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa9490 at wayne.edu Mon Mar 25 15:23:30 2013 From: fa9490 at wayne.edu (Rama Nanditha Danda) Date: Mon, 25 Mar 2013 10:23:30 -0400 (EDT) Subject: [Python.NET] How to Compile python for .Net in VS 2010 in .Net 4.0 Message-ID: <1528044003.1575910.1364221410802.JavaMail.root@wayne.edu> Hello, I downloaded from SVN, and tried to compile it in VS2010.I have Python 2.6.6 version on 64 bit windows 7. I changed projects framework t0 4.0 I changed clrmodule.il version to 4:0:0:0 changed post build events command line to %windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /dll /quiet /output="$(TargetDir)clr.pyd" "$(ProjectDir)clrmodule.il" I made above changes and rebuilded it.Python.exe is closing when i hit clr.AddReference Could anyone , please guide me here. Thank you, Rama Danda From lizy10b at 126.com Thu Mar 28 13:31:39 2013 From: lizy10b at 126.com (lizy10b) Date: Thu, 28 Mar 2013 20:31:39 +0800 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code Message-ID: <201303282031386024899@126.com> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Thu Mar 28 15:15:12 2013 From: brad at fie.us (Bradley Friedman) Date: Thu, 28 Mar 2013 10:15:12 -0400 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code In-Reply-To: <201303282031386024899@126.com> References: <201303282031386024899@126.com> Message-ID: <87D7E93F-F56B-44D7-B170-40E1DFFD4B96@fie.us> 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" 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 at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From lizy10b at 126.com Thu Mar 28 19:09:31 2013 From: lizy10b at 126.com (lizy10b) Date: Fri, 29 Mar 2013 02:09:31 +0800 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code References: <201303282031386024899@126.com> Message-ID: <201303290209201244849@126.com> 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" 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 at python.org http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Mar 28 22:35:29 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 28 Mar 2013 14:35:29 -0700 Subject: [Python.NET] How to run a command by Embedded Python? Message-ID: Hi, I wrote a code PythonWrapper and SimplePythonTest which uses PythonWrapper. using SimplePython; namespace SimplePythonTest { /// /// Python Wrapper Tests /// [TestFixture] public class PythonTests { PythonWrapper py; /// /// PythonTests Constructor /// public PythonTests() { py = new PythonWrapper(); py.Init(); PyObject po; po = py.LoadModule("os"); po = py.LoadModule("sys"); po = py.LoadModule("psutil"); } /// /// Python Simple Test /// [Test] public void CommonPythonTests() { PyObject po = py.Execute("os.getcwd()"); Trace.WriteLine(po.Repr()); py.Close(); } } } namespace SimplePython { /// /// Python Wrapper via XMLRPC/Python 2.7.3/.Net for Python. /// public class PythonWrapper { /// /// Inter Lock /// private IntPtr gs; /// /// Constructor /// public PythonWrapper() { } /// /// Initialize PythonEngine /// public void Init() { PythonEngine.Initialize(); gs = PythonEngine.AcquireLock(); } /// /// Load Module /// /// Module Name /// public PyObject LoadModule(string strModule) { return PythonEngine.ImportModule(strModule); } /// /// Execute Python Command /// /// Python Command /// public PyObject Execute(string strCommand) { PyObject po = PythonEngine.RunString(strCommand); return po; } public void Close() { PythonEngine.ReleaseLock(gs); PythonEngine.Shutdown(); } } } When testing (CommonPythonTests), it initializes and loads modules, but PythonEngine.RunString() doesn't seem to work properly. Is any something wrong in my code which gets os.getcwd()? Furthermore, I can't find the difference between PythonEngine.RunString() and PythonEngine.RunSimpleString(). Thank you, Spark. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Thu Mar 28 22:34:51 2013 From: brad at fie.us (brad at fie.us) Date: Thu, 28 Mar 2013 17:34:51 -0400 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code In-Reply-To: <201303290209201244849@126.com> References: <201303282031386024899@126.com> <201303290209201244849@126.com> Message-ID: <8CB3B037-7118-44A2-A0E2-7E6F29A99364@fie.us> In my code I'm running: Python.Runtime.PythonEngine.Initialize(); I also have these defined: public void AddPythonPath(string path) { CheckInitPython(); IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); Python.Runtime.PythonEngine.RunSimpleString("import sys"); Python.Runtime.PythonEngine.RunSimpleString("sys.path.append(\"" + path.Replace("\\", "\\\\") + "\")"); Python.Runtime.PythonEngine.ReleaseLock(l); } public Python.Runtime.PyObject ImportModule(string name) { CheckInitPython(); IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); Python.Runtime.PyObject module = Python.Runtime.PythonEngine.ImportModule(name); Python.Runtime.PythonEngine.ReleaseLock(l); if (module == null) { throw new libscclient.PythonModuleNotCreatedException(name); } return module; } And when my code loads a "plugin" python module, it runs this: string pythonVersionBasePath = GetPythonCodeBaseVersionPath(); //my dynamic plugin code. string scriptName = GetPythonScriptName(); //also my dynamic plugin code. System.Console.WriteLine("importing module"); Pedestal.AddPythonPath(pythonVersionBasePath); //calling code above Python.Runtime.PyObject module = Pedestal.ImportModule(scriptName.Split(new char[] { '.' }, 2)[0]); //calling code above System.Console.WriteLine("module imported"); IntPtr l = Pedestal.GetPythonLock(); module.InvokeMethod(GetPythonInitMethodName(), new Python.Runtime.PyObject[] { Python.Runtime.PyObject.FromManagedObject(this) }); //calling a method by name. the name comes from my dynamic plugin code. module.Dispose(); //I'm done with the module so I toss it. my code here registers callbacks. Pedestal.ReleasePythonLock(l); On Mar 28, 2013, at 2:09 PM, "lizy10b" wrote: > 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" 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 at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Mar 28 23:22:56 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 28 Mar 2013 15:22:56 -0700 Subject: [Python.NET] How to run a command by Embedded Python? In-Reply-To: References: Message-ID: BTW, PyObject po = PythonEngine.RunString(strCommand); returns 'null' when running "os.getcwd()", and PythonEngine.RunSimpleString(strCommand) returns '-1'. Currently, I'm working on Async ways to execute a python command (some commands take long to finish a task such as switch configuration, once executing a command, and returns, then gets a result later). Would you give me some suggestions how/what would be best idea for Async wrapper using Python.RunTime? Thanks, Spark. On Thu, Mar 28, 2013 at 2:35 PM, Seungweon Park wrote: > Hi, > > I wrote a code PythonWrapper and SimplePythonTest which uses PythonWrapper. > > > using SimplePython; > > namespace SimplePythonTest > { > /// > /// Python Wrapper Tests > /// > [TestFixture] > public class PythonTests > { > PythonWrapper py; > /// > /// PythonTests Constructor > /// > public PythonTests() > { > py = new PythonWrapper(); > > py.Init(); > > PyObject po; > po = py.LoadModule("os"); > po = py.LoadModule("sys"); > po = py.LoadModule("psutil"); > } > > /// > /// Python Simple Test > /// > [Test] > public void CommonPythonTests() > { > PyObject po = py.Execute("os.getcwd()"); > Trace.WriteLine(po.Repr()); > > py.Close(); > } > } > } > > > namespace SimplePython > { > /// > /// Python Wrapper via XMLRPC/Python 2.7.3/.Net for Python. > /// > public class PythonWrapper > { > /// > /// Inter Lock > /// > private IntPtr gs; > > /// > /// Constructor > /// > public PythonWrapper() > { > } > > /// > /// Initialize PythonEngine > /// > public void Init() > { > PythonEngine.Initialize(); > gs = PythonEngine.AcquireLock(); > > } > > /// > /// Load Module > /// > /// Module Name > /// > public PyObject LoadModule(string strModule) > { > return PythonEngine.ImportModule(strModule); > } > > /// > /// Execute Python Command > /// > /// Python Command > /// > public PyObject Execute(string strCommand) > { > PyObject po = PythonEngine.RunString(strCommand); > > return po; > } > > public void Close() > { > PythonEngine.ReleaseLock(gs); > PythonEngine.Shutdown(); > } > } > } > > When testing (CommonPythonTests), it initializes and loads modules, but > PythonEngine.RunString() doesn't seem to work properly. Is any something > wrong in my code which gets os.getcwd()? Furthermore, I can't find the > difference between PythonEngine.RunString() and > PythonEngine.RunSimpleString(). > > Thank you, > Spark. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Thu Mar 28 22:49:01 2013 From: brad at fie.us (brad at fie.us) Date: Thu, 28 Mar 2013 17:49:01 -0400 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code In-Reply-To: <8CB3B037-7118-44A2-A0E2-7E6F29A99364@fie.us> References: <201303282031386024899@126.com> <201303290209201244849@126.com> <8CB3B037-7118-44A2-A0E2-7E6F29A99364@fie.us> Message-ID: Sorry. One more. When my code then executes those callbacks, back into Python, it does so this way: System.Console.WriteLine("Getting Projects"); List ret = new List(); //the things I expect python to give me back System.Console.WriteLine("Getting lock"); IntPtr p = this.Pedestal.GetPythonLock(); System.Console.WriteLine("Got Lock"); if (this.ProjectsRequested != null) { foreach (libcontextutils.GetProjectSettingsDelegate del in this.ProjectsRequested.GetInvocationList()) //looping through callbacks on delegate { System.Console.WriteLine("Calling Project Delegate"); ret.AddRange(del(projectsType, this)); //doing the callback, which is a python callback in truth. } } else { System.Console.Error.WriteLine("No delegates registered to ProjectsRequested Event."); } System.Console.WriteLine("Releasing lock"); this.Pedestal.ReleasePythonLock(p); System.Console.WriteLine("Released Lock"); return ret; On Mar 28, 2013, at 5:34 PM, "brad at fie.us" wrote: > In my code I'm running: > > Python.Runtime.PythonEngine.Initialize(); > > I also have these defined: > > public void AddPythonPath(string path) > { > CheckInitPython(); > IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); > Python.Runtime.PythonEngine.RunSimpleString("import sys"); > Python.Runtime.PythonEngine.RunSimpleString("sys.path.append(\"" + path.Replace("\\", "\\\\") + "\")"); > Python.Runtime.PythonEngine.ReleaseLock(l); > } > > public Python.Runtime.PyObject ImportModule(string name) > { > CheckInitPython(); > IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); > Python.Runtime.PyObject module = Python.Runtime.PythonEngine.ImportModule(name); > Python.Runtime.PythonEngine.ReleaseLock(l); > if (module == null) > { > throw new libscclient.PythonModuleNotCreatedException(name); > } > return module; > } > > And when my code loads a "plugin" python module, it runs this: > > string pythonVersionBasePath = GetPythonCodeBaseVersionPath(); //my dynamic plugin code. > string scriptName = GetPythonScriptName(); //also my dynamic plugin code. > System.Console.WriteLine("importing module"); > Pedestal.AddPythonPath(pythonVersionBasePath); //calling code above > Python.Runtime.PyObject module = Pedestal.ImportModule(scriptName.Split(new char[] { '.' }, 2)[0]); //calling code above > System.Console.WriteLine("module imported"); > IntPtr l = Pedestal.GetPythonLock(); > module.InvokeMethod(GetPythonInitMethodName(), new Python.Runtime.PyObject[] { Python.Runtime.PyObject.FromManagedObject(this) }); //calling a method by name. the name comes from my dynamic plugin code. > module.Dispose(); //I'm done with the module so I toss it. my code here registers callbacks. > Pedestal.ReleasePythonLock(l); > > On Mar 28, 2013, at 2:09 PM, "lizy10b" wrote: > >> 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" 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 at python.org >>> http://mail.python.org/mailman/listinfo/pythondotnet > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Thu Mar 28 23:38:24 2013 From: brad at fie.us (brad at fie.us) Date: Thu, 28 Mar 2013 18:38:24 -0400 Subject: [Python.NET] How to run a command by Embedded Python? In-Reply-To: References: Message-ID: <3A875222-6CE0-4EB8-B763-3CDDB1D11064@fie.us> Doesn't it just depend on where you want the async to be? On the python side or on the .net side? You could do it all in the python side and just stick to python async methodologies. Or you could do it in .net in which case you need to use the multi-threaded aspects of pythonnet. -brad On Mar 28, 2013, at 6:22 PM, Seungweon Park wrote: > BTW, PyObject po = PythonEngine.RunString(strCommand); returns 'null' when running "os.getcwd()", and PythonEngine.RunSimpleString(strCommand) returns '-1'. > > Currently, I'm working on Async ways to execute a python command (some commands take long to finish a task such as switch configuration, once executing a command, and returns, then gets a result later). > Would you give me some suggestions how/what would be best idea for Async wrapper using Python.RunTime? > > Thanks, > Spark. > > On Thu, Mar 28, 2013 at 2:35 PM, Seungweon Park wrote: > Hi, > > I wrote a code PythonWrapper and SimplePythonTest which uses PythonWrapper. > > > using SimplePython; > > namespace SimplePythonTest > { > /// > /// Python Wrapper Tests > /// > [TestFixture] > public class PythonTests > { > PythonWrapper py; > /// > /// PythonTests Constructor > /// > public PythonTests() > { > py = new PythonWrapper(); > > py.Init(); > > PyObject po; > po = py.LoadModule("os"); > po = py.LoadModule("sys"); > po = py.LoadModule("psutil"); > } > > /// > /// Python Simple Test > /// > [Test] > public void CommonPythonTests() > { > PyObject po = py.Execute("os.getcwd()"); > Trace.WriteLine(po.Repr()); > > py.Close(); > } > } > } > > > namespace SimplePython > { > /// > /// Python Wrapper via XMLRPC/Python 2.7.3/.Net for Python. > /// > public class PythonWrapper > { > /// > /// Inter Lock > /// > private IntPtr gs; > > /// > /// Constructor > /// > public PythonWrapper() > { > } > > /// > /// Initialize PythonEngine > /// > public void Init() > { > PythonEngine.Initialize(); > gs = PythonEngine.AcquireLock(); > > } > > /// > /// Load Module > /// > /// Module Name > /// > public PyObject LoadModule(string strModule) > { > return PythonEngine.ImportModule(strModule); > } > > /// > /// Execute Python Command > /// > /// Python Command > /// > public PyObject Execute(string strCommand) > { > PyObject po = PythonEngine.RunString(strCommand); > > return po; > } > > public void Close() > { > PythonEngine.ReleaseLock(gs); > PythonEngine.Shutdown(); > } > } > } > > When testing (CommonPythonTests), it initializes and loads modules, but PythonEngine.RunString() doesn't seem to work properly. Is any something wrong in my code which gets os.getcwd()? Furthermore, I can't find the difference between PythonEngine.RunString() and PythonEngine.RunSimpleString(). > > Thank you, > Spark. > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From lizy10b at 126.com Fri Mar 29 10:42:14 2013 From: lizy10b at 126.com (lizy10b) Date: Fri, 29 Mar 2013 17:42:14 +0800 Subject: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code References: <201303282031386024899@126.com>, <201303290209201244849@126.com>, <8CB3B037-7118-44A2-A0E2-7E6F29A99364@fie.us> Message-ID: <201303291742140032077@126.com> Thanks for your code, Bradley I followed your sample, add the path first , then PythonEngine.ImportModule, spending all the day in embeding the third part C-based library into my C# code, but PythonEngine.ImportModule still return Null. I wrote a simple test C dll (only one function returns a+1), and a wrapper py file using the ctypes. Then load the py file in C#, the PythonEngine.ImportModule does return a non-null value, but when invoke the function is saids can not find the dll. When I put the dll in the Python root dir (on my end is C:\Python262\) , the py file runs smoothly. I try to add the path of the dll into sys.path, but does not work, only putting it into the Python root dir works. So I think the situation is: third part C-base python library (in my case, rtree and psycopg2) uses more complex ctypes warpper, so maybe the python.net is incomptible to it? or I still have some chance to make it work, maybe still the sys.path problem? Thanks Zhiyu Li 2013-03-29 lizy10b ???? brad at fie.us ????? 2013-03-29 06:03:32 ???? lizy10b ??? pythondotnet ??? Re: [Python.NET] how to load and execute py file which consumes a thrid part C-based python extension in C# code Sorry. One more. When my code then executes those callbacks, back into Python, it does so this way: System.Console.WriteLine("Getting Projects"); List ret = new List(); //the things I expect python to give me back System.Console.WriteLine("Getting lock"); IntPtr p = this.Pedestal.GetPythonLock(); System.Console.WriteLine("Got Lock"); if (this.ProjectsRequested != null) { foreach (libcontextutils.GetProjectSettingsDelegate del in this.ProjectsRequested.GetInvocationList()) //looping through callbacks on delegate { System.Console.WriteLine("Calling Project Delegate"); ret.AddRange(del(projectsType, this)); //doing the callback, which is a python callback in truth. } } else { System.Console.Error.WriteLine("No delegates registered to ProjectsRequested Event."); } System.Console.WriteLine("Releasing lock"); this.Pedestal.ReleasePythonLock(p); System.Console.WriteLine("Released Lock"); return ret; On Mar 28, 2013, at 5:34 PM, "brad at fie.us" wrote: In my code I'm running: Python.Runtime.PythonEngine.Initialize(); I also have these defined: public void AddPythonPath(string path) { CheckInitPython(); IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); Python.Runtime.PythonEngine.RunSimpleString("import sys"); Python.Runtime.PythonEngine.RunSimpleString("sys.path.append(\"" + path.Replace("\\", "\\\\") + "\")"); Python.Runtime.PythonEngine.ReleaseLock(l); } public Python.Runtime.PyObject ImportModule(string name) { CheckInitPython(); IntPtr l = Python.Runtime.PythonEngine.AcquireLock(); Python.Runtime.PyObject module = Python.Runtime.PythonEngine.ImportModule(name); Python.Runtime.PythonEngine.ReleaseLock(l); if (module == null) { throw new libscclient.PythonModuleNotCreatedException(name); } return module; } And when my code loads a "plugin" python module, it runs this: string pythonVersionBasePath = GetPythonCodeBaseVersionPath(); //my dynamic plugin code. string scriptName = GetPythonScriptName(); //also my dynamic plugin code. System.Console.WriteLine("importing module"); Pedestal.AddPythonPath(pythonVersionBasePath); //calling code above Python.Runtime.PyObject module = Pedestal.ImportModule(scriptName.Split(new char[] { '.' }, 2)[0]); //calling code above System.Console.WriteLine("module imported"); IntPtr l = Pedestal.GetPythonLock(); module.InvokeMethod(GetPythonInitMethodName(), new Python.Runtime.PyObject[] { Python.Runtime.PyObject.FromManagedObject(this) }); //calling a method by name. the name comes from my dynamic plugin code. module.Dispose(); //I'm done with the module so I toss it. my code here registers callbacks. Pedestal.ReleasePythonLock(l); On Mar 28, 2013, at 2:09 PM, "lizy10b" wrote: 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" 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 at python.org http://mail.python.org/mailman/listinfo/pythondotnet _________________________________________________ Python.NET mailing list - PythonDotNet at python.org http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: