Hello, I'm trying to figure out how can I use Python.NET, and I'm having weird problems: This run ok: <script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { PythonEngine.Initialize(); PyObject p = PythonEngine.ImportModule("sys"); PyObject c = p.GetAttr("path"); string s = c.ToString(); Response.Write(s); PythonEngine.Finalize(); } </script> It outputs: ['D:\\testsite\\bin\\python23.zip', '.\\DLLs', '.\\lib', '.\\lib\\plat-win', '.\\lib\\lib-tk', '\\\\?\\C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322'] But when I'm trying to run the script foo.py which is located under the above '\lib' I'm getting "Exception of type Python.Runtime.PythonException was thrown." at the line: PyObject p = PythonEngine.ImportModule("foo"); How can I learn more about the exception cause? Thank you, -- Laurian Gridinoc Chief Developer GRAPEFRUIT DESIGN www.grapefruitdesign.com
Hi Laurian, Try removing the call to PythonEngine.Finalize(). That should _only_ be called when you are truly finished with the Python interpreter (to clean up and free resources, etc.) That method tears down the Python runtime environment and after it is called you can't use Python anymore from any thread in the process. - Brian
I'm trying to figure out how can I use Python.NET, and I'm having weird problems:
This run ok:
<script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) {
PythonEngine.Initialize();
PyObject p = PythonEngine.ImportModule("sys"); PyObject c = p.GetAttr("path");
string s = c.ToString(); Response.Write(s);
PythonEngine.Finalize(); }
</script>
It outputs: ['D:\\testsite\\bin\\python23.zip', '.\\DLLs', '.\\lib', '.\\lib\\plat-win', '.\\lib\\lib-tk', '\\\\?\\C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322']
But when I'm trying to run the script foo.py which is located under the above '\lib' I'm getting "Exception of type Python.Runtime.PythonException was thrown." at the line:
PyObject p = PythonEngine.ImportModule("foo");
How can I learn more about the exception cause?
Thank you, -- Laurian Gridinoc Chief Developer GRAPEFRUIT DESIGN www.grapefruitdesign.com
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com
On Mon, 2004-05-17 at 14:17, Brian Lloyd wrote:
Try removing the call to PythonEngine.Finalize(). That should _only_ be called when you are truly finished with the Python interpreter (to clean up and free resources, etc.) That method tears down the Python runtime environment and after it is called you can't use Python anymore from any thread in the process. - Brian
The issue was with sys.path which when called from aspx, and not from an exe was relative (.\lib, instead of d:\testsite\bin\lib) so I have to set it like this before importing my module: PyObject sys = PythonEngine.ImportModule("sys"); PyObject path = sys.GetAttr("path"); PyObject append = path.GetAttr("append"); PyObject[] a = new PyObject[1]; a[0] = new PyString("d:\\testsite\\bin\\lib"); append.Invoke(a); Response.Write(path.ToString()); Another issue, if I tear down the python runtime environment (not by several finalize(), but by recurrent errors) how can I restore it without restarting my application (in ASP.NET it seems I have to restart the WWW Publishing service for this) Thank you, -- Laurian Gridinoc Chief Developer GRAPEFRUIT DESIGN www.grapefruitdesign.com
participants (2)
-
Brian Lloyd
-
Laurian Gridinoc