Installing MySQLdb under Cygwin

Discussion in 'Python' started by Perflubron, Oct 10, 2003.

  1. Perflubron

    Perflubron Guest

    Hi,

    I'm having trouble installing MySQLdb 0.9.2 on the following Cygwin system:
    - Python 2.2.2
    - MySQL 3.23.57
    - gcc 2.95.3-10

    The steps I take are:
    1. Modify setup.py
    - Set thread_safe_library = NO
    - Change the Cygwin paths to use /cygdrive/c/...
    - Change the library path to .../lib/opt

    2. Run setup.py build
    --> Errors on lines 2005-7 and 2094-6 of _mysql.c:
    "Initializer element is not constant"

    3. Replace the above lines with "0,"

    4. Run setup.py build
    --> Many undefined references to mysql functions

    5. Change setup.py to use mysql library instead of mysqlclient

    6. Run setup.py build
    --> It compiles, so I run the setup.py install

    7. When I try to import the library, I get the following error:
    Traceback (most recent call last):
    File "./test.py", line 4, in ?
    import MySQLdb
    File "MySQLdb/__init__.py", line 27, in ?
    import _mysql
    ImportError: dlopen: Win32 error 127

    I'm stuck. I've tried using g++ instead of gcc, which gets rid of the
    Initializer element is not constant" error. But I end up at the same error
    when I try to import the module.

    I have seen some posts from people who have managed to install MySQLdb on
    Cygwin - could someone please let me know how to do it?

    Kind regards,

    Per
     
    Perflubron, Oct 10, 2003
    #1
    1. Advertising

  2. Per,

    On Fri, Oct 10, 2003 at 11:09:17AM -0700, Perflubron wrote:
    > 7. When I try to import the library, I get the following error:
    > Traceback (most recent call last):
    > File "./test.py", line 4, in ?
    > import MySQLdb
    > File "MySQLdb/__init__.py", line 27, in ?
    > import _mysql
    > ImportError: dlopen: Win32 error 127


    We have the following:

    $ fgrep 127 /usr/include/w32api/winerror.h | head -1
    #define ERROR_PROC_NOT_FOUND 127L

    This error usually means the extension module did not export the init
    function. What do you get when you try the following?

    $ objdump -p _mysql.dll | fgrep init

    For example:

    $ objdump -p zlib.dll | fgrep init
    [ 0] initzlib

    If the init function is not being exported, then change the source from:

    void
    init_mysql(void)
    {
    ...
    }

    to:

    DL_EXPORT(void) /* for Python 2.2.2, use PyMODINIT_FUNC for Python 2.3+ */
    init_mysql(void)
    {
    ...
    }

    > I have seen some posts from people who have managed to install MySQLdb
    > on Cygwin - could someone please let me know how to do it?


    See the following mailing list thread:

    http://cygwin.com/ml/cygwin/2003-10/msg00462.html

    Try the Cygwin list if you need more help.

    Jason

    --
    PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
    Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
     
    Jason Tishler, Oct 10, 2003
    #2
    1. Advertising

  3. Perflubron

    Perflubron Guest

    Hi Jason,

    > This error usually means the extension module did not export the init
    > function. What do you get when you try the following?
    >
    > $ objdump -p _mysql.dll | fgrep init


    I get:

    ba58 52 mysql_init
    [ 0] init_mysql__Fv

    I don't know what the __Fv means.

    > If the init function is not being exported, then change the source from:
    >
    > to:
    >
    > DL_EXPORT(void) /* for Python 2.2.2, use PyMODINIT_FUNC for Python 2.3+ */
    > init_mysql(void)
    > {
    > ...
    > }
    >


    The source already has the DL_EXPORT line in it.

    I'll try the cygwin list now, thanks for your help.

    Per
     
    Perflubron, Oct 13, 2003
    #3
  4. Per,

    On Mon, Oct 13, 2003 at 01:53:48AM -0700, Perflubron wrote:
    > I get:
    >
    > ba58 52 mysql_init
    > [ 0] init_mysql__Fv
    >
    > I don't know what the __Fv means.


    The "__Fv" is the name mangling produced by g++. Try again with gcc.
    Or, add 'extern "C"' to the init function definition. What does objdump
    indicate now?

    Jason

    --
    PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
    Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
     
    Jason Tishler, Oct 13, 2003
    #4
  5. Perflubron

    Perflubron Guest

    Hi Jason,

    > The "__Fv" is the name mangling produced by g++. Try again with gcc.
    > Or, add 'extern "C"' to the init function definition. What does objdump
    > indicate now?


    g++ with extern "C" does not compile at first attempt. With gcc, I
    overcame the "initializer element is not constant errors" by setting
    the elements of the struct after creating it, e.g:

    _mysql_ConnectionObject_Type.tp_alloc = &PyType_GenericAlloc;

    But the objdump is still the same:
    ba58 52 mysql_init
    [ 0] init_mysql

    I've given up on using MySQLdb under Cygwin. I instead installed the
    Windows version of Python and MySQLdb, and will use that combination
    for certain scripts.

    Thanks for all your help!

    Per
     
    Perflubron, Oct 14, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. usenet
    Replies:
    2
    Views:
    3,526
    usenet
    May 22, 2005
  2. Replies:
    0
    Views:
    515
  3. dw

    mysqldb on cygwin

    dw, Feb 17, 2004, in forum: Python
    Replies:
    0
    Views:
    773
  4. Matthew Roth
    Replies:
    9
    Views:
    896
    John Nagle
    Jan 26, 2011
  5. Phil Tomson
    Replies:
    2
    Views:
    128
    Phil Tomson
    Apr 6, 2004
Loading...

Share This Page