Huge problem gettng MySQLdb to work on my mac mini running Macosx10.5 Leopard

G

geert

Hi all,

I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as 64-bit.

MySQLdb installs with the usual warnings after applying the various
patches I found here and there. These patches consist of altering
_mysql.c and site.cfg.

Basically, my problem boils down to this:

File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line
19, in <module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in
<module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in
__bootstrap__
ImportError: dynamic module does not define init function (init_mysql)


Has anyone solved this? I been hunting around for 2 weeks now, and my
deadline is looming grimly on the horizon :)

Geert
 
R

Robert Rawlins

Geert,

I've not seen this issue myself, however, you might get a little more luck
asking over on the MySQLdb mailing list as this seems to be more an issue
with the db than your python code. It might be worth posting your question
there too as it'll heighten your chances of finding someone who knows
MySQLdb inside out.

http://mail.python.org/mailman/listinfo/db-sig

Cheers,

Robert

-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk@python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk@python.org]
On Behalf Of geert
Sent: 14 March 2008 10:36
To: (e-mail address removed)
Subject: Huge problem gettng MySQLdb to work on my mac mini running Macosx
10.5 Leopard

Hi all,

I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as 64-bit.

MySQLdb installs with the usual warnings after applying the various
patches I found here and there. These patches consist of altering
_mysql.c and site.cfg.

Basically, my problem boils down to this:

File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line
19, in <module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in
<module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in
__bootstrap__
ImportError: dynamic module does not define init function (init_mysql)


Has anyone solved this? I been hunting around for 2 weeks now, and my
deadline is looming grimly on the horizon :)

Geert
 
G

geert

Geert,

I've not seen this issue myself, however, you might get a little more luck
asking over on theMySQLdbmailing list as this seems to be more an issue
with the db than your python code. It might be worth posting your question
there too as it'll heighten your chances of finding someone who knowsMySQLdbinside out.

http://mail.python.org/mailman/listinfo/db-sig

Cheers,

Robert

-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co...@python.org

[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co...@python.org]
On Behalf Of geert
Sent: 14 March 2008 10:36
To: (e-mail address removed)
Subject: Huge problem gettngMySQLdbto work on my mac mini running Macosx
10.5 Leopard

Hi all,

I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as 64-bit.

MySQLdbinstalls with the usual warnings after applying the various
patches I found here and there. These patches consist of altering
_mysql.c and site.cfg.

Basically, my problem boils down to this:

  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line
19, in <module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in
<module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in
__bootstrap__
ImportError: dynamic module does not define init function (init_mysql)

Has anyone solved this? I been hunting around for 2 weeks now, and my
deadline is looming grimly on the horizon :)

Geert

--http://mail.python.org/mailman/listinfo/python-list

Thanks, Robert. I'm on the MySQLdb list, and am working on a solution.
And I've subscribed to the list you gave.

Geert
 
G

geert

look athttp://groups.google.be/group/comp.lang.python/browse_thread/thread/d...

There is a macpython list that you can consult athttp://www.nabble.com/Python---pythonmac-sig-f2970.html

Just wanted to let you know that I've solved my problem. The solution
is to compile mysql using

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking --enable-thread-safe-client
--prefix=/usr/local/mysql

You then go this way to get it running on your machine:

http://hivelogic.com/articles/installing-mysql-on-mac-os-x/

Then reinstall MySQLdb. Magic!

Geert
 
G

geert

Just wanted to let you know that I've solved my problem. The solution
is to compile mysql using

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking  --enable-thread-safe-client
--prefix=/usr/local/mysql

You then go this way to get it running on your machine:

http://hivelogic.com/articles/installing-mysql-on-mac-os-x/

Then reinstall MySQLdb. Magic!

Geert

Seems that I've yelled success to quickly. Everything's ok as long as
I just run the django dev server, but moving to apache through
mod_wsgi brings a well-known but less than comforting complaint:

[Tue Mar 18 23:34:25 2008] [error] [client ::1] mod_wsgi (pid=2352):
Exception occurred processing WSGI script '/Users/geert/Sites/LithoNET/
LN/LNApache.wsgi'., referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] Traceback (most recent
call last):, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/wsgi.py", line 205, in
__call__, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
self.get_response(request), referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/base.py", line 64, in
get_response, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
middleware_method(request), referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/middleware.py", line
13, in process_request, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] engine =
__import__(settings.SESSION_ENGINE, {}, {}, ['']), referer:
http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line
2, in <module>, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from
django.contrib.sessions.models import Session, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/models.py", line 5,
in <module>, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from django.db
import models, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/__init__.py", line 17, in <module>,
referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] backend =
__import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {},
{}, ['']), referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/backends/mysql/base.py", line 12,
in <module>, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] raise
ImproperlyConfigured("Error loading MySQLdb module: %s" % e), referer:
http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Library/WebServer/.python-eggs/
MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): no
suitable image found. Did find:, referer: http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] \t/Library/
WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-
tmp/_mysql.so: no matching architecture in universal wrapper, referer:
http://localhost/images/

mmmmmm


Geert
 
G

Graham Dumpleton

On Mar 14, 1:15 pm, (e-mail address removed) wrote:
Just wanted to let you know that I've solved my problem. The solution
is to compile mysql using
MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking --enable-thread-safe-client
--prefix=/usr/local/mysql
You then go this way to get it running on your machine:

Then reinstall MySQLdb. Magic!

Seems that I've yelled success to quickly. Everything's ok as long as
I just run the django dev server, but moving to apache throughmod_wsgibrings a well-known but less than comforting complaint:

[Tue Mar 18 23:34:25 2008] [error] [client ::1]mod_wsgi(pid=2352):
Exception occurred processing WSGI script '/Users/geert/Sites/LithoNET/
LN/LNApache.wsgi'., referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] Traceback (most recent
call last):, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/wsgi.py", line 205, in
__call__, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
self.get_response(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/base.py", line 64, in
get_response, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
middleware_method(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/middleware.py", line
13, in process_request, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] engine =
__import__(settings.SESSION_ENGINE, {}, {}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line
2, in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from
django.contrib.sessions.models import Session, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/models.py", line 5,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from django.db
import models, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/__init__.py", line 17, in <module>,
referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] backend =
__import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {},
{}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/backends/mysql/base.py", line 12,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] raise
ImproperlyConfigured("Error loading MySQLdb module: %s" % e), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Library/WebServer/.python-eggs/
MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): no
suitable image found. Did find:, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] \t/Library/
WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-
tmp/_mysql.so: no matching architecture in universal wrapper, referer:http://localhost/images/

Did you again confirm that running:

file /Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-
macosx-10.5-i386.egg-tmp/_mysql.so

shows the .so having the required architectures, specifically what
Apache runs as (eg. x86_64)?

Do the gcc compiler flags when building and linking the .so file show
all the architecture flags?

Have you empty the Python egg cache to make sure it isn't an older
compiled version?

Graham
 
G

geert

Seems that I've yelled success to quickly. Everything's ok as long as
I just run the django dev server, but moving to apache throughmod_wsgibrings a well-known but less than comforting complaint:
[Tue Mar 18 23:34:25 2008] [error] [client ::1]mod_wsgi(pid=2352):
Exception occurred processing WSGI script '/Users/geert/Sites/LithoNET/
LN/LNApache.wsgi'., referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] Traceback (most recent
call last):, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/core/handlers/wsgi.py", line 205, in
__call__, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     response =
self.get_response(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/core/handlers/base.py", line 64, in
get_response, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     response =
middleware_method(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/contrib/sessions/middleware.py", line
13, in process_request, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     engine =
__import__(settings.SESSION_ENGINE, {}, {}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line
2, in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     from
django.contrib.sessions.models import Session, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/contrib/sessions/models.py", line 5,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     from django.db
import models, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/db/__init__.py", line 17, in <module>,
referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     backend =
__import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {},
{}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]   File "/Library/
Python/2.5/site-packages/django/db/backends/mysql/base.py", line 12,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1]     raise
ImproperlyConfigured("Error loading MySQLdb module: %s" % e), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Library/WebServer/.python-eggs/
MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): no
suitable image found.  Did find:, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] \t/Library/
WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-
tmp/_mysql.so: no matching architecture in universal wrapper, referer:http://localhost/images/

Did you again confirm that running:

  file /Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-
macosx-10.5-i386.egg-tmp/_mysql.so

shows the .so having the required architectures, specifically what
Apache runs as (eg. x86_64)?

Do the gcc compiler flags when building and linking the .so file show
all the architecture flags?

Have you empty the Python egg cache to make sure it isn't an older
compiled version?

Graham

Hi all,

GOT IT!

I have every running now. So, to sum it all up:

I'm on a new intel mac with a 64-bit capable processor running macosx
10.5.2.

I have httpd (apache2) running as a 64 bit app, which it would of
course on a 64-bit machine. Activity monitor confirms this.

I compiled mysql from source, configured as stated below:

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking --enable-thread-safe-
client
--prefix=/usr/local/mysql

Then came mod_wsgi, just out of the box.

Then came MySQLdb.

Extracted the tar, then edited _mysql.c. Commented lines 37 - 39:

//#ifndef uint
//#define uint unsigned int
//#endif

and changed this:
uint port = MYSQL_PORT;
uint client_flag = 0;

to this:
unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;

on lines 484 and 485

Then - but I don't know if this is really (always) necessary, in
site.cfg I changed Threadsafe = True to False.

I set the ARCHFLAGS, but I don't think this helped one inch.

ARCHFLAGS='-arch ppc -arch ppc64 -arch i386 -arch x86_64'


OK. So then I went sudo python setup.py build. (I realise that the
sudo isn't required just to do a build)

There, I noticed this:

creating build/temp.macosx-10.5-i386-2.5
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-
madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -
DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -pipe -
Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/
include/mysql -I/System/Library/Frameworks/Python.framework/Versions/
2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.5-i386-2.5/
_mysql.o -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64

You see, here _mysql.o is being created. If you do file _mysql.o, you
get:

/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o: Mach-O universal binary with 4 architectures
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture i386): Mach-O object i386
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture x86_64): Mach-O 64-bit object
x86_64
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture ppc7400): Mach-O object ppc
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture ppc64): Mach-O 64-bit object ppc64

which is ok.

But, strangely, when _mysql.so is created in the next step, gcc
doesn't add all the arch flags:

gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc
build/temp.macosx-10.5-i386-2.5/_mysql.o -L/usr/local/mysql/lib/mysql -
lmysqlclient -lz -lm -o build/lib.macosx-10.5-i386-2.5/_mysql.so

and you end up with this:

geert-dekkerss-imac:MySQL-python-1.2.2 geert$ file /Users/geert/
Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/_mysql.so
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so: Mach-O universal binary with 2 architectures
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so (for architecture i386): Mach-O bundle i386
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so (for architecture ppc7400): Mach-O bundle ppc

which is most definitely NOT ok.

So I did this:

sudo gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch ppc -arch
ppc64 -arch i386 -arch x86_64 build/temp.macosx-10.5-i386-2.5/_mysql.o
-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -o build/
lib.macosx-10.5-i386-2.5/_mysql.so

adding the arch flags myself, and running gcc again, under sudo.

and lo and behold....

geert-dekkerss-imac:MySQL-python-1.2.2 geert$ file /Users/
geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/
_mysql.so
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so: Mach-O universal binary with 4 architectures
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture ppc7400): Mach-O bundle ppc
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture ppc64): Mach-O 64-bit bundle
ppc64
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture i386): Mach-O bundle i386
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture x86_64): Mach-O 64-bit bundle
x86_64


Well, it only took 20 years off my life span and all the hairs on my
head :)

Geert
 
G

Graham Dumpleton

On Mar 14, 1:15 pm, (e-mail address removed) wrote:
look athttp://groups.google.be/group/comp.lang.python/browse_thread/thread/d...
There is a macpython list that you can consult athttp://www.nabble.com/Python---pythonmac-sig-f2970.html
Just wanted to let you know that I've solved my problem. The solution
is to compile mysql using
MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking --enable-thread-safe-client
--prefix=/usr/local/mysql
You then go this way to get it running on your machine:
http://hivelogic.com/articles/installing-mysql-on-mac-os-x/
Then reinstall MySQLdb. Magic!
Geert
Seems that I've yelled success to quickly. Everything's ok as long as
I just run the django dev server, but moving to apache throughmod_wsgibrings a well-known but less than comforting complaint:
[Tue Mar 18 23:34:25 2008] [error] [client ::1]mod_wsgi(pid=2352):
Exception occurred processing WSGI script '/Users/geert/Sites/LithoNET/
LN/LNApache.wsgi'., referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] Traceback (most recent
call last):, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/wsgi.py", line 205, in
__call__, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
self.get_response(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/core/handlers/base.py", line 64, in
get_response, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] response =
middleware_method(request), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/middleware.py", line
13, in process_request, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] engine =
__import__(settings.SESSION_ENGINE, {}, {}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line
2, in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from
django.contrib.sessions.models import Session, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/contrib/sessions/models.py", line 5,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] from django.db
import models, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/__init__.py", line 17, in <module>,
referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] backend =
__import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {},
{}, ['']), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] File "/Library/
Python/2.5/site-packages/django/db/backends/mysql/base.py", line 12,
in <module>, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] raise
ImproperlyConfigured("Error loading MySQLdb module: %s" % e), referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Library/WebServer/.python-eggs/
MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): no
suitable image found. Did find:, referer:http://localhost/images/
[Tue Mar 18 23:34:25 2008] [error] [client ::1] \t/Library/
WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-
tmp/_mysql.so: no matching architecture in universal wrapper, referer:http://localhost/images/
Did you again confirm that running:
file /Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-
macosx-10.5-i386.egg-tmp/_mysql.so
shows the .so having the required architectures, specifically what
Apache runs as (eg. x86_64)?
Do the gcc compiler flags when building and linking the .so file show
all the architecture flags?
Have you empty the Python egg cache to make sure it isn't an older
compiled version?

Hi all,

GOT IT!

I have every running now. So, to sum it all up:

I'm on a new intel mac with a 64-bit capable processor running macosx
10.5.2.

I have httpd (apache2) running as a 64 bit app, which it would of
course on a 64-bit machine. Activity monitor confirms this.

I compiled mysql from source, configured as stated below:

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --disable-dependency-tracking --enable-thread-safe-
client
--prefix=/usr/local/mysql

Then camemod_wsgi, just out of the box.

Then came MySQLdb.

Extracted the tar, then edited _mysql.c. Commented lines 37 - 39:

//#ifndef uint
//#define uint unsigned int
//#endif

and changed this:
uint port = MYSQL_PORT;
uint client_flag = 0;

to this:
unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;

on lines 484 and 485

Then - but I don't know if this is really (always) necessary, in
site.cfg I changed Threadsafe = True to False.

I set the ARCHFLAGS, but I don't think this helped one inch.

ARCHFLAGS='-arch ppc -arch ppc64 -arch i386 -arch x86_64'

OK. So then I went sudo python setup.py build. (I realise that the
sudo isn't required just to do a build)

There, I noticed this:

creating build/temp.macosx-10.5-i386-2.5
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-
madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -
DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -pipe -
Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/
include/mysql -I/System/Library/Frameworks/Python.framework/Versions/
2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.5-i386-2.5/
_mysql.o -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64

You see, here _mysql.o is being created. If you do file _mysql.o, you
get:

/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o: Mach-O universal binary with 4 architectures
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture i386): Mach-O object i386
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture x86_64): Mach-O 64-bit object
x86_64
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture ppc7400): Mach-O object ppc
/Users/geert/Desktop/MySQL-python-1.2.2/build/temp.macosx-10.5-
i386-2.5/_mysql.o (for architecture ppc64): Mach-O 64-bit object ppc64

which is ok.

But, strangely, when _mysql.so is created in the next step, gcc
doesn't add all the arch flags:

gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc
build/temp.macosx-10.5-i386-2.5/_mysql.o -L/usr/local/mysql/lib/mysql -
lmysqlclient -lz -lm -o build/lib.macosx-10.5-i386-2.5/_mysql.so

and you end up with this:

geert-dekkerss-imac:MySQL-python-1.2.2 geert$ file /Users/geert/
Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/_mysql.so
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so: Mach-O universal binary with 2 architectures
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so (for architecture i386): Mach-O bundle i386
/Users/geert/Desktop/MySQL-python-1.2.2/build/lib.macosx-10.5-i386-2.5/
_mysql.so (for architecture ppc7400): Mach-O bundle ppc

which is most definitely NOT ok.

So I did this:

sudo gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch ppc -arch
ppc64 -arch i386 -arch x86_64 build/temp.macosx-10.5-i386-2.5/_mysql.o
-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -o build/
lib.macosx-10.5-i386-2.5/_mysql.so

adding the arch flags myself, and running gcc again, under sudo.

and lo and behold....

geert-dekkerss-imac:MySQL-python-1.2.2 geert$ file /Users/
geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/
_mysql.so
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so: Mach-O universal binary with 4 architectures
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture ppc7400): Mach-O bundle ppc
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture ppc64): Mach-O 64-bit bundle
ppc64
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture i386): Mach-O bundle i386
/Users/geert/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
i386.egg-tmp/_mysql.so (for architecture x86_64): Mach-O 64-bit bundle
x86_64

Well, it only took 20 years off my life span and all the hairs on my
head :)

I don't have access to MacOS X OS supplied Python 2.5 at moment, but
if distutils used by setup.py is ignoring ARCHFLAGS for the link then
that may be an issue with distutils. More likely though is that MySQL
setup.py is setting some option which is causing ARCHFLAGS to be
ignored.

Strange thing is I can't find ARCHFLAGS in original Python 2.5 source
I have, so checking it may be specific to MacOS X OS supplied Python.

Will need to check when I get home to my Leopard box.

Graham
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top