Hi! Bob As I said, I can import it from command line by
>pythonw >import StringModule > By the way, the StringModule has been installed in the MacPython system as I do a setup. The sys.path print out as following: ============= zhi-pengs-power-mac-g5:~/Desktop/zhiyong/ScriptSupport zpeng$ make gcc -g ScriptSupport.c -c -I./ -I/usr/include -I/usr/include/python2.3 -Wall -Wstrict-prototypes -o ScriptSupport.o gcc -g ScriptSupport.o -L/usr/lib -ldl -lm -lpython -o ScriptSupport ./ScriptSupport ['/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python23.zip', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.3/Extras/lib/python', '.'] cannot import StringModule wave Thanks Zhi --- Bob Ippolito <[EMAIL PROTECTED]> wrote: > If sys.path is correct, then it would import. I > don't believe you, > show the sys.path from the python interpreter and > show it from your > program. > > -bob > > On Dec 12, 2005, at 9:40 AM, Zhi Peng wrote: > > > > > Hi! Bob > > > > Following is the main code that I used for test. > The > > sys.path seems correct because I can import when I > use > > pythonw and import SringModule. Everytime I run > the > > program, it said "can not import > > StringModule". One might use a simple module with > only > > one sentance inside as a "StringModule.py" and > > "StringModule.pyc". > > > > Thanks > > > > Zhi > > > > > ====================================================== > > > > > > #include <Python.h> > > > > > > int main() > > { > > PyObject > > *myMod=NULL,*myClass=NULL,*myModuleInstance=NULL; > > > > > > Py_Initialize(); > > > > PyRun_SimpleString("import sys \n"); > > > > > PyRun_SimpleString("sys.path.append('.\')\n"); > > PyRun_SimpleString("print sys.path \n"); > > > > //myMod=PyImport_ImportModule("os"); > > > > > myMod=PyImport_ImportModule("StringModule"); > > if(!myMod) { printf("cannot import > > StringModule\n"); return TRUE; } > > return 0; > > > > } > > > > > > > > The 'StringModule' is in the right directory as > > following: > > ================================================== > > > zhi-pengs-power-mac-g5:/System/Library/Frameworks/Python.framework/ > > > Versions/2.3/lib/python2.3 > > > > zpeng$ find . -name 'StringModule.py' -print > > ./StringModule.py > > > > > zhi-pengs-power-mac-g5:/System/Library/Frameworks/Python.framework/ > > > Versions/2.3/lib/python2.3 > > > > > > zpeng$ find . -name 'StringModule.pyc' -print > > ./StringModule.pyc > > > > > > > > > > --- Bob Ippolito <[EMAIL PROTECTED]> wrote: > > > >> Well I have no idea whether you're extending or > >> embedding Python.. > >> and if you are embedding, I have no idea what > steps > >> you've taken to > >> initialize the interpreter... so I'm not sure. > >> > >> Like I said before, what you need to do is make > >> absolutely sure > >> you're using the correct Python interpreter, > >> framework, or dylib and > >> also make sure that sys.path is setup properly. > >> This might help:: > >> > >> PyRun_SimpleString("import sys\nprint > >> sys.path\nprint sys.version > >> \nprint sys.executable\n"); > >> > >> -bob > >> > >> On Dec 9, 2005, at 8:45 PM, Zhi Peng wrote: > >> > >>> Hi! Bob > >>> > >>> I have not tried to append current directory in > >> sys.path. Maybe I > >>> need to do sth > >>> sys.path.append("./") and then do import. The > >> module is installed > >>> in MacPython package. The os module is in > >> python23.dylib so it can > >>> find it and import it. But my module is just a > py > >> file. > >>> > >>> Thanks > >>> > >>> > >>> Zhi > >>> > >>> Bob Ippolito <[EMAIL PROTECTED]> wrote: > >>> > >>> On Dec 9, 2005, at 4:41 PM, Zhi Peng wrote: > >>> > >>>> In my c code, I have used > >> myMod=PyImport_ImportModule("moduleName") > >>>> and run on Mac, but it just can not import the > >> "moduleName" for > >>>> some unknown reason. > >>>> > >>>> I am sure I install the "moduleName" by > "pythonw > >> setup install". > >>>> And I can import "moduleName" from command > lines > >> such as > >>>> > >>>>> pythonw > >>>>> import moduleName > >>>>> > >>>> > >>>> It is fine. I wonder why PyImport_ImportModule > >> can not import it, > >>>> while it can import module os by using > >>>> PyImport_ImportModule("os") > >>>> > >>>> Any suggestion? > >>>> > >>> > >>> Are you sure it's the same version of Python, > and > >> the module is on > >>> sys.path? Check sys.version and sys.path > >>> > >>> -bob > >>> > >>> > >>> > >>> Yahoo! Shopping > >>> Find Great Deals on Holiday Gifts at Yahoo! > >> Shopping > >>> _______________________________________________ > >>> Pythonmac-SIG maillist - > >> Pythonmac-SIG@python.org > >>> > >> > > > http://mail.python.org/mailman/listinfo/pythonmac-sig > >> > >> > > > > > > __________________________________________________ > > Do You Yahoo!? > > Tired of spam? Yahoo! Mail has the best spam > protection around > > http://mail.yahoo.com > > _______________________________________________ > > Pythonmac-SIG maillist - > Pythonmac-SIG@python.org > > > http://mail.python.org/mailman/listinfo/pythonmac-sig > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig