[Chicago] python and c import error

=?gb2312?q?=B7=C5=DC=F8=20=CC=B8?= jolley84 at yahoo.com.cn
Tue Nov 14 13:36:42 CET 2006


here is a script which shows the creation  of a frame.
  with its name app.py
  import wx
  class MyApp(wx.App):
           def OnInit(self,title = "MyApp"):
                 self.app = wx.PySimpleApp()
                 self.title = title
                 self.windowCaption = title
                 wx.Frame.__init__(self,None,self.ID_ANY,self.windowCaption,
                                            size = (200,100),
                                            style = wx.DEFAULT_WINDOW_STYLE|
                                         wx.NO_FULL_REPAINT_NO_RESIZE)
  app = MyApp(0)
  app.MainLoop()
  hmm,the python script is povided by Robert ,thanks again for the valuable revision on my former script,it's ugly and not smart.
  and then when i intend to use it in c extension.so,i start by
  #include "python.h"
  #include <stdio.h>
  #define ERROR(object,msg) {if(object == NULL) {printf("%s",msg);PyErr_Print();exit(1);}}
  int main()
  {
       PyInitialize();
       if(!PyInitialized())
             {
                    printf("initialization of python fails!");
                    exit(1);
             }
      //load the module.
      PyObject *pModule,*pAddedModule,*pClass,*pMethod,*pArgs,*pInstance;
      pModule = PyImport_ImportModule("app");
     ERROR(pModule,"the module can not be loaded!")
  //imo wx is a library embedded in the python library,so i donot intend to add it to the module
  //load the imported wx library
  pAddedModule = PyImport_AddModule("wx");
  ERROR(pAddedModule,"the module can not be loaded!")
  //load the class
  pClass = PyObject_GetAttrString(pModule,"MyApp");
  ERROR(pClass ,"the class can not be loaded!")
  Py_DECREF(pModule);
  //load the method
  pArgs= Py_BuildValue("()");
  ERROR(pArgs,"the format is not decided!");
  pInstance = PyEval_CallObject(pClass,pArgs);
  ERROR(pInstance,"the instance of the class can not be loaded!")
  Py_DECREF(pClass);
  Py_DECREF(pArgs);
  pMethod = PyObject_GetAttrString(pInstance,"OnInit");
  Py_DECREF(pInstance);
  ERROR(pMethod,"method can not be loaded!");
  PyEval_CallObject(pMethod);
  Py_DECREF(pMethod);
  Py_Finalize();
  return 0;
  }
  and the problem came when loading the "app"module,and it crashed because of the import of wx.what's more, the detailed error message is "ImportError:no module named "_core_"",while actually.it really resides in my pythonLib/lib/site-packages/.
  thanks if anyone can help me,and i have spent 3days pondering over this matter,and my headached.
  regards,
  jolley

 		
---------------------------------
 ÑÅ»¢Ãâ·ÑÓÊÏä-3.5GÈÝÁ¿£¬20M¸½¼þ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/chicago/attachments/20061114/1f67826a/attachment.html 


More information about the Chicago mailing list