Error importing MySQLdb when embedding python

Moe Hendawi yohamed at concentric.net
Tue May 2 19:23:26 EDT 2000


Hi there,

I am trying to embed python in a C++ application.  Here is the gist of the
C++:

        Py_Initialize();
        PyRun_SimpleFile(fh, "handler.py");
        Py_Finalize();

handler.py is as follows:

    import sys
    import MySQLdb
    print "Hello"

When I do this, I get the following error:

    moe: embed [19]>./embedpython
    Traceback (innermost last):
      File "test2.py", line 3, in ?
        import MySQLdb
      File
"/usr/local/packages/Python-1.5.2/lib/python1.5/site-packages/MySQLdb.py",
line 19, in ?
        import _mysql
    ImportError:
/usr/local/packages/Python-1.5.2/lib/python1.5/site-packages/_mysqlmodule.so
: undefined symbol: PyType_Type

If I take out the "import MySQLdb" line, the problem goes away (duh).  If I
run handler.py directly from the command-line it works fine so MySQLdb is
set up properly (I have written more complicated scripts that demonstrate it
working).  I'm not really sure what the error message is telling me about
PyType_Type.  Does anyone have any ideas what is going on?  This is my first
real attempt at using Python so I may be attempting a bit much at first, but
I have a need for embedding and I would prefer to take this opportunity to
learn Python (as opposed to doing it in Perl which I know cold).

Thanks for any help!

-Moe  (please cc: yohamed AT concentric DOT net)









More information about the Python-list mailing list