473,714 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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.p y multiply 3 2
and as a result :
ValueError: Empty module name
Failed to load "./TestPythonFoo.p y"
if I try an absolute path to the python file :
../TestOfficiel `pwd`/TestPythonFoo.p y multiply 3 2
I obtain :
ImportError: No module named
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y
Failed to load
"/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y"
Of course the file exist :
[montmory@esoppe 1 swigCallPython]$ ll
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y
-rwxrwx--x 1 montmory esoppe 126 sep 29 14:04
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y*

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_FromSt ring(argv[1]);
/* Error checking of pName left out */

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

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

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

if (pFunc && PyCallable_Chec k(pFunc)) {
pArgs = PyTuple_New(arg c - 3);
for (i = 0; i < argc - 3; ++i) {
pValue = PyInt_FromLong( atoi(argv[i + 3]));
if (!pValue) {
Py_DECREF(pArgs );
Py_DECREF(pModu le);
fprintf(stderr, "Cannot convert argument\n");
return 1;
}
/* pValue reference stolen here: */
PyTuple_SetItem (pArgs, i, pValue);
}
pValue = PyObject_CallOb ject(pFunc, pArgs);
Py_DECREF(pArgs );
if (pValue != NULL) {
printf("Result of call: %ld\n", PyInt_AsLong(pV alue));
Py_DECREF(pValu e);
}
else {
Py_DECREF(pModu le);
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(pModu le);
}
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 17249
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.p y multiply 3 2
and as a result :
ValueError: Empty module name
Failed to load "./TestPythonFoo.p y"
This is (I believe) because of the "." at the front.
if I try an absolute path to the python file :
./TestOfficiel `pwd`/TestPythonFoo.p y multiply 3 2
I obtain :
ImportError: No module named
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y
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.p y"
Of course the file exist :
[montmory@esoppe 1 swigCallPython]$ ll
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y
-rwxrwx--x 1 montmory esoppe 126 sep 29 14:04
/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.p y*

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


--------------070105030901000 008070407
Content-Type: text/plain
Content-Disposition: inline;
filename="TestO fficiel.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_FromSt ring(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__("f oo")
hello fubar world
<module 'foo' from 'foo.py'>
>>__import__("f oo.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
5048
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, sometimes not. From mysql: mysql> show databases; +-----------+ | Database |
1
2184
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 about the calling scope. If you look at my function "test" below, I'd ideally like log messages: foo.py:test, "message 1" foo.py:Foo.__init__, "message 2" foo.py:Foo.bar, "message 3"
13
5801
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 a Access 2k Runtime, my machine is in XP Pro and Access 2k): when I try to close a form use "Alt+C" key, there is a error saying "module not found" (It is Ok if I click the close_form sign "X" on the up right corner of the form). This problem is...
7
2175
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. Here's what I discovered. In addition to my main web project and several middle tier projects, I also added an "empty" web project in my solution (Add - New Project - Empty Web Project). This empty web project is what is causing the above...
1
2597
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
5425
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. They will only need to be run once per execution. Example (directory level): Sys1: A B C
0
1812
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 environment for Python 2.3.3) and our extensions (C++ code) on Windows with Microsoft Visual C++ 6.0 compiler to generate the extended Python interpreter. It works well on Linux and for the basic Python modules and our special modules on Windows. But...
0
1109
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 do not want to add that whole folder's stuff to the sys.path) ..pth adds only directories to the python path. is there a convenient/short method to create a python "module pointer" (file) to such module - maybe just create such pointer file...
1
2351
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 main module through: from support import *
0
8704
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6627
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3155
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.