I'm trying to run the embedding example and I can't load a module from the current working directory unless I explicitly add it to sys.path
then it works:
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(".")");
Shouldn't Python look for modules in the current directory ?
Edit1: Tried just importing the module with:
Py_Initialize();
PyRun_SimpleString("import multiply");
And it still fails with the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named multiply
Edit2: From the sys.path
docs:
If the script directory is not available (e.g. if the interpreter is
invoked interactively or if the script is read from standard input),
path[0] is the empty string, which directs Python to search modules
in the current directory first.
Not sure what it means by not available, but if I print sys.path[0]
it's not empty:
/usr/lib/pymodules/python2.7
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…