[Pythonmac-SIG] import problems

Zhi Peng zhiyong_peng2003 at yahoo.com
Mon Dec 12 19:30:54 CET 2005


Hi! All 

If you use MacPython2.3 on MAc, please try the
following code to see if you can get "StringModule"
imported. 

//=============================StringModule.py===========
#!pythonw

import os 

class Module1:
    def __init__(self):
        self.var1= 9
    def method1(self):
        self.var1=10;





//========================= makefile
====================
YLIB =


PYINC=-I./ -I/usr/include -I/usr/include/python2.3
LIBS =-L/usr/lib -ldl -lm -lpython

OPTS= -Wall -Wstrict-prototypes

PROGRAM=ScriptSupport
ScriptSupport::ScriptSupport.o
        gcc -g ScriptSupport.o $(LIBS) $(PYLIB) -o
ScriptSupport
ScriptSupport.o:ScriptSupport.c
        gcc -g ScriptSupport.c -c $(PYINC) $(OPTS) -o
ScriptSupport.o
clean:
        rm -f $(PROGRAM) *.o core





//================ ScriptSupport.c
========================

#include <Python.h>

#define FALSE  0
#define TRUE  1

int main(void)
{
        PyObject *myMod=NULL;


        Py_Initialize();

        PyRun_SimpleString("import sys \n");

        PyRun_SimpleString("sys.path.append('.\')\n");
        PyRun_SimpleString("print sys.path \n");

        //#myMod=PyImport_ImportModule("wave");

        myMod=PyImport_ImportModule("StringModule");
        if(!myMod) { printf("cannot import
StringModule wave\n"); return TRUE; }

        Py_Finalize();

        return 0;
}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Pythonmac-SIG mailing list