473,382 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

"ValueError: Empty module name" on basic import

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
http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding
I download the code example from
http://www.python.org/doc/2.4.2/ext/run-func.txt
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"
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
Failed to load
"/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py"
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


#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");
return 1;
}

Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */

pModule = PyImport_Import(pName);
Py_DECREF(pName);

if (pModule != NULL) {
pDict = PyModule_GetDict(pModule);
/* pDict is a borrowed reference */

pFunc = PyDict_GetItemString(pDict, argv[2]);
/* pFun: Borrowed reference */

if (pFunc && PyCallable_Check(pFunc)) {
pArgs = PyTuple_New(argc - 3);
for (i = 0; i < argc - 3; ++i) {
pValue = PyInt_FromLong(atoi(argv[i + 3]));
if (!pValue) {
Py_DECREF(pArgs);
Py_DECREF(pModule);
fprintf(stderr, "Cannot convert argument\n");
return 1;
}
/* pValue reference stolen here: */
PyTuple_SetItem(pArgs, i, pValue);
}
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL) {
printf("Result of call: %ld\n", PyInt_AsLong(pValue));
Py_DECREF(pValue);
}
else {
Py_DECREF(pModule);
PyErr_Print();
fprintf(stderr,"Call failed\n");
return 1;
}
/* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
}
else {
if (PyErr_Occurred())
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
}
Py_DECREF(pModule);
}
else {
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
Py_Finalize();
return 0;
}

def multiply(a,b):
print "Will compute", a, "times", b
c = 0
for i in range(0, a):
c = c + b
return c

Sep 29 '06 #1
1 17159
alain MONTMORY wrote:
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
http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding
I download the code example from
http://www.python.org/doc/2.4.2/ext/run-func.txt
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"
This is (I believe) because of the "." at the front.
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
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
Failed to load
"/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py"
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");
"pythonfile" is confusing; it should be "modulename".

return 1;
}

Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */

pModule = PyImport_Import(pName);
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.
>>__import__("foo")
hello fubar world
<module 'foo' from 'foo.py'>
>>__import__("foo.py")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named py
>>__import__("")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
>>__import__(r".\foo")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
>>__import__(r"./foo")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
>>__import__(r"/foo")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named /foo
>>__import__(r".foo")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Empty module name
>>>
Hmmm ... "empty module name" is rather misleading when it starts with a
"." -- I can feel a bugfix^^^^^^ enhancement request coming on :-)

HTH,
John

Sep 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
1
by: Darran Edmundson | last post by:
I was playing around with the inspect module the other day trying to write a quick and dirty "smart" logger. By this I mean that writing a message to the global log would also yield some info...
13
by: Paul T. RONG | last post by:
Hello there, This is the case: the mde I made works alright on my machine, but there is a small problem when I installed it on a user's machine (His machine's OS is Windows XP Pro and it has...
7
by: Brad | last post by:
When debugging my current web project, in VS2003, I found I had lost the ability to drill down on watch objects in the Watch Window; I could only view the single value specific watch objects. ...
1
by: Xiao Jianfeng | last post by:
Hello, In pymol I can use "from chempy import Atom" but "import chempy.Atom" doesn't work. It says,"ImportError: No module named Atom". What is going wrong ? Thanks
3
by: Mudcat | last post by:
I have a directory structure that contains different modules that run depending on what the user selects. They are identical in name and structure, but what varies is the content of the functions....
0
by: Terry Tang | last post by:
Hi There, We are extending Python interpreter to support special functions of our tools. What we did is to compile Python's source code (which is got from the an installation on a Linux...
0
by: robert | last post by:
I want to occasionally do a "redirected" import of a python module which is located offside of the legacy sys.path (Windows) - for example a tool is maintained within "cgi-bin" web stuff (while I...
1
by: lemke_juergen | last post by:
Hi everyone, I define some vars and functions in a "support" module which gets called from my main app module. Using Python 2.5. I import all symbols in the support module at the top of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.