<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<br>
alain MONTMORY a écrit :
<blockquote cite="mid451D3B25.5090307@thalesgroup.com" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
Thank for your response <span class="moz-smiley-s1"><span> :-) </span></span><br>
<br>
I have tried (it's my first try ..) :<br>
<pre wrap="">./TestOfficiel TestPythonFoo multiply 3 2</pre>
and i get :<br>
[montmory@esoppe1 swigCallPython]$ ./TestOfficiel TestPythonFoo
multiply 3 2<br>
ImportError: No module named TestPythonFoo<br>
Failed to load "TestPythonFoo"<br>
<br>
Then i tried what you suggest below :<br>
[montmory@esoppe1 swigCallPython]$ python<br>
Python 2.3.4 (#2, Aug 19 2004, 15:49:40)<br>
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2<br>
Type "help", "copyright", "credits" or "license" for more information.<br>
>>> __import__("TestPythonFoo")<br>
<module 'TestPythonFoo' from 'TestPythonFoo.pyc'><br>
<br>
and it works !!!<br>
why this doesn't work with the api <br>
<pre wrap="">pModule = PyImport_Import(pName);
</pre>
<pre wrap="">pModule is null after the call
</pre>
<br>
is there a PYTHONPATH to set or semething else...<br>
</blockquote>
I put :<br>
export PYTHONPATH=$PYTHONPATH:<dot><br>
and it works,<br>
thank you,<br>
your response put me on the way...<br>
<br>
<br>
<blockquote cite="mid451D3B25.5090307@thalesgroup.com" type="cite"><br>
thanks <br>
<br>
Alain<br>
<br>
John Machin a écrit :
<blockquote
cite="mid1159541352.702121.246240@i3g2000cwc.googlegroups.com"
type="cite">
<pre wrap="">alain MONTMORY wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hello everybody,
I am a newbie to python so I hope I am at the right place to expose my
problem..... :-[
I am working on linux mandrake 10.1 with python :
python -V
Python 2.3.4
I am trying o run the example which stay in the documentation in paragraph
<a class="moz-txt-link-freetext"
href="http://www.python.org/doc/2.4.2/ext/pure-embedding.html">http://www.python.org/doc/2.4.2/ext/pure-embedding.html</a> 5.3 Pure Embedding
I download the code example from
<a class="moz-txt-link-freetext"
href="http://www.python.org/doc/2.4.2/ext/run-func.txt">http://www.python.org/doc/2.4.2/ext/run-func.txt</a>
I call the file "TestOfficiel.c" and I compile it with :
gcc -g -I/usr/include/python2.3/ TestOfficiel.c -o TestOfficiel
-lpython2.3 -ldl
all is OK (or seems to be...).
as stated in the documentation I creat a file "TestPythonFoo.py" which
contain
"
def multiply(a,b):
print "Will compute", a, "times", b
c = 0
for i in range(0, a):
c = c + b
return c
"
I launch
./TestOfficiel ./TestPythonFoo.py multiply 3 2
and as a result :
ValueError: Empty module name
Failed to load "./TestPythonFoo.py"
</pre>
</blockquote>
<pre wrap=""><!---->
This is (I believe) because of the "." at the front.
</pre>
<blockquote type="cite">
<pre wrap="">if I try an absolute path to the python file :
./TestOfficiel `pwd`/TestPythonFoo.py multiply 3 2
I obtain :
ImportError: No module named
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py
</pre>
</blockquote>
<pre wrap=""><!---->
It's quite correct, there never could be a module named that. The name
of your module is TestPythonFoo -- so all you should have to do is
./TestOfficiel TestPythonFoo multiply 3 2
</pre>
<blockquote type="cite">
<pre wrap="">Failed to load
"/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py"
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">Of course the file exist :
[montmory@esoppe1 swigCallPython]$ ll
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py
-rwxrwx--x 1 montmory esoppe 126 sep 29 14:04
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py*
I found lot of post about "ValueError: Empty module name" but no clear
solution (clear for me...).
What's wrong ?
my python version?
Additionnal informations :
gcc version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)
Thanks for your help,
best regards,
Alain
--------------070105030901000008070407
Content-Type: text/plain
Content-Disposition: inline;
filename="TestOfficiel.c"
X-Google-AttachSize: 2022
#include <Python.h>
int
main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
int i;
if (argc < 3) {
fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
</pre>
</blockquote>
<pre wrap=""><!---->
"pythonfile" is confusing; it should be "modulename".
</pre>
</blockquote>
Yes you are right, but i left the example file "as it is"<br>
<blockquote
cite="mid1159541352.702121.246240@i3g2000cwc.googlegroups.com"
type="cite">
<blockquote type="cite">
<pre wrap=""> return 1;
}
Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */
pModule = PyImport_Import(pName);
</pre>
</blockquote>
<pre wrap=""><!---->
As the docs for this function say, it just calls the same routine that
is called by the __import__ built-in function. One can experiment with
that:
OS-prompt>copy con foo.py
print 'hello fubar world'
^Z
1 file(s) copied.
OS-prompt>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__("foo")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->hello fubar world
<module 'foo' from 'foo.py'>
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__("foo.py")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named py
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__("")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__(r".\foo")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__(r"./foo")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__(r"/foo")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named /foo
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">__import__(r".foo")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
</pre>
<pre wrap=""><!---->
Hmmm ... "empty module name" is rather misleading when it starts with a
"." -- I can feel a bugfix^^^^^^ enhancement request coming on :-)
HTH,
John
</pre>
</blockquote>
</blockquote>
</body>
</html>