Installing MySQLdb under Cygwin

P

Perflubron

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
 
J

Jason Tishler

Per,

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
 
P

Perflubron

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
 
J

Jason Tishler

Per,

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
 
P

Perflubron

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top