Discussion:
[Python.NET] PyTables working with python not working with python.net
Guillaume Pichard
2011-03-25 20:14:29 UTC
Permalink
Hello,

I am trying to use pytables with python.net. It is working great with python
alone. What I am doing with python.net is:
PythonEngine.Initialize();
PythonEngine.AcquireLock();

PyObject sys = PythonEngine.ImportModule("sys");
PyObject path = sys.GetAttr("path");
PyObject append = path.GetAttr("append");
PyObject[] a = new PyObject[1];
a[0] = new PyString("C:\\Python27\\Lib\\site-packages");
append.Invoke(a);

PyObject pyTables = PythonEngine.ImportModule("tables");
if (pyTables == null)
throw new PythonException();

The exception message is "ImportError : DLL load failed: Specified module
not found."

What could be the differences between python.net and python ? Is there any
specific path to add ?

Thanks a lot,
Guillaume.
Tanmoy
2011-03-27 14:31:15 UTC
Permalink
python is written in pure C/C++. The point is to integrate C# codes in
python.net. do go thru the list and u will be able to find ur answer.

T

On Sat, Mar 26, 2011 at 1:44 AM, Guillaume Pichard
Post by Guillaume Pichard
Hello,
I am trying to use pytables with python.net. It is working great with
PythonEngine.Initialize();
PythonEngine.AcquireLock();
PyObject sys = PythonEngine.ImportModule("sys");
PyObject path = sys.GetAttr("path");
PyObject append = path.GetAttr("append");
PyObject[] a = new PyObject[1];
a[0] = new PyString("C:\\Python27\\Lib\\site-packages");
append.Invoke(a);
PyObject pyTables = PythonEngine.ImportModule("tables");
if (pyTables == null)
throw new PythonException();
The exception message is "ImportError : DLL load failed: Specified module
not found."
What could be the differences between python.net and python ? Is there any
specific path to add ?
Thanks a lot,
Guillaume.
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--
Tanmoy Mukherjee
Barton
2011-03-28 02:48:51 UTC
Permalink
I do believe (although I'm not an embedder myself) that this is the ol'
"Can't use unicode strings on import statements" thing...
This is the reason for a new class called PyAnsiString().

You'll have to have a fairly recent version to see if that fixes things
for you.
HTH,
Barton
Post by Tanmoy
python is written in pure C/C++. The point is to integrate C# codes in
python.net <http://python.net>. do go thru the list and u will be able
to find ur answer.
T
On Sat, Mar 26, 2011 at 1:44 AM, Guillaume Pichard
Hello,
I am trying to use pytables with python.net <http://python.net>.
It is working great with python alone. What I am doing with
PythonEngine.Initialize();
PythonEngine.AcquireLock();
PyObject sys = PythonEngine.ImportModule("sys");
PyObject path = sys.GetAttr("path");
PyObject append = path.GetAttr("append");
PyObject[] a = new PyObject[1];
a[0] = new PyString("C:\\Python27\\Lib\\site-packages");
append.Invoke(a);
PyObject pyTables = PythonEngine.ImportModule("tables");
if (pyTables == null)
throw new PythonException();
The exception message is "ImportError : DLL load failed: Specified
module not found."
What could be the differences between python.net
<http://python.net> and python ? Is there any specific path to add ?
Thanks a lot,
Guillaume.
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--
Tanmoy Mukherjee
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Barton
2011-04-02 09:46:03 UTC
Permalink
Being a novice embedder (especially back when I wrote the pyimport.cs
module in the Python.EmbeddingTest project), I chose to do things a
little differently:
At the time, I felt like I wanted access to the entire engine.
I still can't decide if calling methods on PyObject is more clumsy than
the object[] arg passing arrangement with strongly typed object or not.

[SetUp]
public void SetUp() {
PythonEngine.Initialize();
gs = PythonEngine.AcquireLock();

//string here = Environment.CurrentDirectory;
// trunk\pythonnet\src\embed_tests\bin\Debug

/*
* Append the tests directory to sys.path
* using reflection to circumvent the private modifiers placed on
most Runtime methods.
*/
string s = @"..\..\..\tests";

Type RTClass = typeof(Runtime.Runtime);

/* pyStrPtr = PyString_FromString(s); */
MethodInfo PyString_FromString =
RTClass.GetMethod("PyString_FromString", BindingFlags.NonPublic |
BindingFlags.Static);
object[] funcArgs = new object[1];
funcArgs[0] = s;
IntPtr pyStrPtr = (IntPtr)PyString_FromString.Invoke(null, funcArgs);

/* SysDotPath = sys.path */
MethodInfo PySys_GetObject = RTClass.GetMethod("PySys_GetObject",
BindingFlags.NonPublic | BindingFlags.Static);
funcArgs[0] = "path";
IntPtr SysDotPath = (IntPtr)PySys_GetObject.Invoke(null, funcArgs);

/* SysDotPath.append(*pyStrPtr) */
MethodInfo PyList_Append = RTClass.GetMethod("PyList_Append",
BindingFlags.NonPublic | BindingFlags.Static);
funcArgs = new object[2];
funcArgs[0] = SysDotPath;
funcArgs[1] = pyStrPtr;
int r = (int)PyList_Append.Invoke(null, funcArgs);
}
[TearDown]
public void TearDown()
{
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
}
[Test]
public void TestDottedName() {
PyObject module;
module = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module, ">>> import PyImportTest.test.one #
FAILED");
}

Personally, I don't see the benefit of marking most of the Runtime as
private.
Post by Guillaume Pichard
Hello,
I am trying to use pytables with python.net <http://python.net>. It is
working great with python alone. What I am doing with python.net
PythonEngine.Initialize();
PythonEngine.AcquireLock();
PyObject sys = PythonEngine.ImportModule("sys");
PyObject path = sys.GetAttr("path");
PyObject append = path.GetAttr("append");
PyObject[] a = new PyObject[1];
a[0] = new PyString("C:\\Python27\\Lib\\site-packages");
append.Invoke(a);
PyObject pyTables = PythonEngine.ImportModule("tables");
if (pyTables == null)
throw new PythonException();
The exception message is "ImportError : DLL load failed: Specified
module not found."
What could be the differences between python.net <http://python.net> and
python ? Is there any specific path to add ?
Thanks a lot,
Guillaume.
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...