MacOS X Leopard + mod_pyton + mysql problems

18 views
Skip to first unread message

crudolph

unread,
Oct 30, 2007, 10:53:53 AM10/30/07
to Django users
Hi,

I was able to get django/python running via mod_python under the
apache2 installation under Leopard (MacOS X 10.5). However once I
start to add database support to my project - I get the following
error.

ImproperlyConfigured: Error loading MySQLdb module: dlopen(/tmp/
egg_cache/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so,
2): no suitable image found. Did find:
/tmp/egg_cache/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/
_mysql.so: no matching architecture in universal wrapper

Anyone have any luck figuring this out?

Thanks,
Chris.

-- Full Error Listing --

MOD_PYTHON ERROR

ProcessId: 28674
Interpreter: 'mysite'

ServerName: 'Lepperd.local'
DocumentRoot: '/Library/WebServer/Documents'

URI: '/webdocs/mysite/'
Location: '/webdocs/mysite'
Directory: None
Filename: '/Library/WebServer/Documents/webdocs/mysite/'
PathInfo: ''

Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'

Traceback (most recent call last):

File "/Library/Python/2.5/site-packages/mod_python/importer.py",
line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "/Library/Python/2.5/site-packages/mod_python/importer.py",
line 1229, in _process_target
result = _execute_target(config, req, object, arg)

File "/Library/Python/2.5/site-packages/mod_python/importer.py",
line 1128, in _execute_target
result = object(arg)

File "/Library/Python/2.5/site-packages/django/core/handlers/
modpython.py", line 177, in handler
return ModPythonHandler()(req)

File "/Library/Python/2.5/site-packages/django/core/handlers/
modpython.py", line 145, in __call__
self.load_middleware()

File "/Library/Python/2.5/site-packages/django/core/handlers/
base.py", line 29, in load_middleware
mod = __import__(mw_module, {}, {}, [''])

File "/Library/Python/2.5/site-packages/django/contrib/sessions/
middleware.py", line 2, in <module>
from django.contrib.sessions.models import Session

File "/Library/Python/2.5/site-packages/django/contrib/sessions/
models.py", line 3, in <module>
from django.db import models

File "/Library/Python/2.5/site-packages/django/db/__init__.py", line
11, in <module>
backend = __import__('django.db.backends.%s.base' %
settings.DATABASE_ENGINE, {}, {}, [''])

File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
base.py", line 12, in <module>
raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e

ImproperlyConfigured: Error loading MySQLdb module: dlopen(/tmp/
egg_cache/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so,
2): no suitable image found. Did find:
/tmp/egg_cache/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp/
_mysql.so: no matching architecture in universal wrapper

Joseph Heck

unread,
Oct 30, 2007, 1:29:49 PM10/30/07
to django...@googlegroups.com
Hey Chris,

How did you install the MySQL/Python library? Did you use MacPorts? A
pre-made binary?

Miller Hooks

unread,
Oct 30, 2007, 2:12:18 PM10/30/07
to django...@googlegroups.com
I had some issues with mysqldb when I was setting it up on my mac, this
article helped me a lot.

http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx

The comments on it were really the key.

crudolph

unread,
Oct 30, 2007, 3:57:16 PM10/30/07
to Django users
Yeah - I downloaded from http://sourceforge.net/projects/mysql-python,
unzipped and ran python setup.py build and then install.

Under Leopard (10.5) apache2 is 4-way, so it is running in 64-bit
mode. I haven't been able to figure out how to pass the right
architecture flags through setup.py

cc -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 -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 -Os -arch i386 -fno-common
gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc -
arch ppc64 -arch x86_64 build/temp.macosx-10.5-i386-2.5/_mysql.o -L/
usr/local/mysql/lib/mysql -lmysqlclient_r -lz -lm -o build/
lib.macosx-10.5-i386-2.5/_mysql.so
ld: warning in build/temp.macosx-10.5-i386-2.5/_mysql.o, file is not
of required architecture
ld: warning in /usr/local/mysql/lib/mysql/libmysqlclient_r.dylib, file
is not of required architecture
ld: warning in build/temp.macosx-10.5-i386-2.5/_mysql.o, file is not
of required architecture
ld: warning in /usr/local/mysql/lib/mysql/libmysqlclient_r.dylib, file
is not of required architecture
ld: warning in build/temp.macosx-10.5-i386-2.5/_mysql.o, file is not
of required architecture
ld: warning in /usr/local/mysql/lib/mysql/libmysqlclient_r.dylib, file
is not of required architecture

Graham Dumpleton

unread,
Oct 30, 2007, 5:42:02 PM10/30/07
to Django users
I am actually surprised you got mod_python working in the first place
unless you did some fiddles you haven't mentioned here. We have been
sorting out issues with mod_python and mod_wsgi not working on Leopard
over on the mod_python list.

Short answer is, try editing src/Makefile in mod_python after running
configure and change:

mod_python.so: $(SRCS)
@echo
@echo 'Compiling for DSO.'
@echo
$(APXS) $(INCLUDES) -c $(SRCS) $(LDFLAGS) $(LIBS)
@rm -f mod_python.so
@ln -s .libs/mod_python.so mod_python.so

to:

mod_python.so: $(SRCS)
@echo
@echo 'Compiling for DSO.'
@echo
$(APXS) $(INCLUDES) -c -Wc,"-arch ppc" -Wc,"-arch ppc64" -Wc,"-
arch i386" -Wc,"-arch x86_64" $(SRCS) $(LDFLAGS) $(LIBS)
@rm -f mod_python.so
@ln -s .libs/mod_python.so mod_python.so

Ie., add the arch options in explicitly.

Recompile and reinstall mod_python and see if that makes a difference.

Graham

On Oct 31, 6:57 am, crudolph <chris.rudo...@gmail.com> wrote:
> Yeah - I downloaded fromhttp://sourceforge.net/projects/mysql-python,

Graham Dumpleton

unread,
Oct 30, 2007, 7:17:59 PM10/30/07
to Django users
On Oct 31, 6:57 am, crudolph <chris.rudo...@gmail.com> wrote:
> Yeah - I downloaded fromhttp://sourceforge.net/projects/mysql-python,

> unzipped and ran python setup.py build and then install.
>
> Under Leopard (10.5) apache2 is 4-way, so it is running in 64-bit
> mode. I haven't been able to figure out how to pass the right
> architecture flags through setup.py

Reading this again, what do you get if run run:

file /usr/local/mysql/lib/mysql/libmysqlclient_r.dylib

The problem is not necessarily passing correct arch flags through
setup.py but that the MySQL client library doesn't contain all
architectures and needs to be recompiled.

Graham

bmit...@gmail.com

unread,
Oct 30, 2007, 10:11:44 PM10/30/07
to Django users
Stuck in the same place.

I'm guessing you d/l'd and installed the MySQL OSX 10.4 x86 installer
package from MySQL. I did. I think it's only i386.

They also have a Universal Binary OSX 10.4 file up there, but only in
Tar format. I'm d/l'ing that now to try. Hopefully it's got the
x86_64 image in it as well.


-Ben

bmit...@gmail.com

unread,
Oct 30, 2007, 11:32:08 PM10/30/07
to Django users
Argh. The "Universal" version of MySQL includes only: ppc, ppc64,
i386

[Macintosh:src/mysql-5.0.45-osx10.4-universal/lib] benha% file
libmysqlclient_r.a
libmysqlclient_r.a: Mach-O universal binary with 3 architectures
libmysqlclient_r.a (for architecture i386): current ar archive
libmysqlclient_r.a (for architecture ppc64): current ar archive
libmysqlclient_r.a (for architecture ppc): current ar archive

So that means that in order to link to the MySQL libs, we'll need to
build/install a 64-bit version of MySQL. Sigh...

Anyone have a set of reliable, working instructions for doing that?

-Ben

SneWs

unread,
Nov 5, 2007, 1:44:56 PM11/5/07
to Django users
It's actually really simple to build the client lib's you need to get
the MySQL support working.

Download the Community Server Source and you can build it from that.

I hade the same problem but for QT and MySQL support,
take a look at, http://demo.grenangen.se/drupal

There you will find a simple instruction set on how to build the
community server source for Leopard.
If that doesn't help, get back to me and I'll try to help further.

Oliver Beattie

unread,
Dec 26, 2007, 5:49:14 PM12/26/07
to Django users
Did anyone ever get this working, I am tearing my hair out here trying
to figure it out; I finally get it to build and now I'm getting:-

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:
/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

Please, please, please, somebody help! I've been using Django for ages
under a 32-bit system and need to get it up and running ASAP...

On Nov 5, 6:44 pm, SneWs <sne...@gmail.com> wrote:
> It's actually really simple to build the client lib's you need to get
> the MySQL support working.
>
> Download the Community Server Source and you can build it from that.
>
> I hade the same problem but for QT and MySQL support,
> take a look at,http://demo.grenangen.se/drupal
>
> There you will find a simple instruction set on how to build the
> community server source for Leopard.
> If that doesn't help, get back to me and I'll try to help further.
>
> On Oct 31, 4:32 am, "bmitch...@gmail.com" <bmitch...@gmail.com> wrote:
>
> > Argh. The "Universal" version of MySQL includes only: ppc, ppc64,
> > i386
>
> > [Macintosh:src/mysql-5.0.45-osx10.4-universal/lib] benha% file
> > libmysqlclient_r.a
> > libmysqlclient_r.a: Mach-O universal binary with 3 architectures
> > libmysqlclient_r.a (for architecture i386): current ar archive
> > libmysqlclient_r.a (for architecture ppc64): current ar archive
> > libmysqlclient_r.a (for architecture ppc): current ar archive
>
> > So that means that in order to link to the MySQL libs, we'll need to
> > build/install a 64-bit version of MySQL. Sigh...
>
> > Anyone have a set of reliable, working instructions for doing that?
>
> > -Ben
>
> > On Oct 30, 7:11 pm, "bmitch...@gmail.com" <bmitch...@gmail.com> wrote:
>
> > > Stuck in the same place.
>
> > > I'm guessing you d/l'd and installed the MySQL OSX 10.4 x86 installer
> > > package from MySQL. I did. I think it's only i386.
>
> > > They also have a Universal Binary OSX 10.4 file up there, but only in
> > > Tar format. I'm d/l'ing that now to try. Hopefully it's got the
> > >x86_64image in it as well.
>
> > > -Ben

Graham Dumpleton

unread,
Dec 26, 2007, 7:18:51 PM12/26/07
to Django users
On Dec 27, 9:49 am, Oliver Beattie <oli...@obeattie.com> wrote:
> Did anyone ever get this working, I am tearing my hair out here trying
> to figure it out; I finally get it to build and now I'm getting:-
>
> 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:
>         /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
>
> Please, please, please, somebody help! I've been using Django for ages
> under a 32-bit system and need to get it up and running ASAP...

The correct answer was that you need to get a version of MySQL Python
client compiled for 64 bit Intel.

If such a thing is still not available for download and you are not
capable of compiling it yourself, the only other option is to thin out
the httpd executable so that it is only i386.

This can be done by the following procedure. Be very careful in doing
this as you are modifying OS files. Only do it if you are really
desperate and keep backups.

cd /usr/sbin

sudo mv ./httpd ./httpd.fat
sudo lipo ./httpd.fat -thin i386 -output ./httpd.i386
sudo ln -s ./httpd.i386 ./httpd

After doing that, you should end up with:

$ file ./httpd.fat
./httpd.fat: Mach-O universal binary with 4 architectures
./httpd.fat (for architecture ppc7400): Mach-O executable ppc
./httpd.fat (for architecture ppc64): Mach-O 64-bit executable ppc64
./httpd.fat (for architecture i386): Mach-O executable i386
./httpd.fat (for architecture x86_64): Mach-O 64-bit executable x86_64

$ file ./httpd.i386
./httpd.i386: Mach-O executable i386

When Apache is now run, it should run as Intel and not Intel (64 bit).
You can check what it runs as using the Activity Monitor application.
Look at the Kind column to see what it runs as.

You then hopefully shouldn't have a problem.

Please indicate if this does help or not.

Graham

Oliver Beattie

unread,
Dec 27, 2007, 4:07:48 AM12/27/07
to Django users
I have compiled it for 64-bit: http://farm3.static.flickr.com/2013/2140077639_7abe03b5fb_o.gif

Yet I still get this error, am I missing something?

I would be reluctant to make force Apache into 32-bit, but if that's
the only option...

On Dec 27, 12:18 am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:

Oliver Beattie

unread,
Dec 27, 2007, 5:35:16 AM12/27/07
to Django users
Right, sorted this out. When running setup.py build, it will spit out
the compilation command it's executing at the bottom of its output.
You will notice that it doesn't include an x86_64 architecture, so you
need to add one. Edit the command so it looks like:

sudo gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch
ppc -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

And run it (notice I added sudo at the beginning, also in theory you
should be okay removing all the other architectures). Then you should
be able to run setup.py install with no problems.

*Phew!*

Graham Dumpleton

unread,
Dec 27, 2007, 6:15:21 AM12/27/07
to Django users
Known issue. Documented at least for older versions of mod_wsgi at:

http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX

Version 2.0 of mod_wsgi includes work around for MacOS X not strictly
doing the right thing. :-)

Graham

ace

unread,
Feb 11, 2008, 6:07:46 PM2/11/08
to Django users
I am getting the following error:

MOD_PYTHON ERROR

ProcessId: 4196
Interpreter: 'ale.local'

ServerName: 'ale.local'
DocumentRoot: '/Library/WebServer/Documents'

URI: '/~ale/newsite/'
Location: '/~ale/newsite/'
Directory: None
Filename: '/Users/ale/Sites/newsite/'
ImproperlyConfigured: Error loading MySQLdb module: dynamic module
does not define init function (init_mysql)



Can anyone help please? Thank you very much in advance!!
Ale



On Dec 27 2007, 11:35 am, Oliver Beattie <oli...@obeattie.com> wrote:
> Right, sorted this out. When running setup.py build, it will spit out
> the compilation command it's executing at the bottom of its output.
> You will notice that it doesn't include an x86_64architecture, so you
> need to add one. Edit the command so it looks like:
>
> sudo gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch
> ppc -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
>
> And run it (notice I added sudo at the beginning, also in theory you
> should be okay removing all the other architectures). Then you should
> be able to run setup.py install withnoproblems.
>
> *Phew!*
>
> On Dec 27, 9:07 am, Oliver Beattie <oli...@obeattie.com> wrote:
>
> > I have compiled it for 64-bit:http://farm3.static.flickr.com/2013/2140077639_7abe03b5fb_o.gif
>
> > Yet I still get this error, am I missing something?
>
> > I would be reluctant to make force Apache into 32-bit, but if that's
> > the only option...
>
> > On Dec 27, 12:18 am, Graham Dumpleton <Graham.Dumple...@gmail.com>
> > wrote:
>
> > > On Dec 27, 9:49 am, Oliver Beattie <oli...@obeattie.com> wrote:
>
> > > > Did anyone ever get this working, I am tearing my hair out here trying
> > > > to figure it out; I finally get it to build and now I'm getting:-
>
> > > > 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):nosuitable image found. Did find:
> > > > /Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-
> > > > i386.egg-tmp/_mysql.so:nomatchingarchitectureinuniversalwrapper
>
> > > > Please, please, please, somebody help! I've been using Django for ages
> > > > under a 32-bit system and need to get it up and running ASAP...
>
> > > The correct answer was that you need to get a version of MySQL Python
> > > client compiled for 64 bit Intel.
>
> > > If such a thing is still not available for download and you are not
> > > capable of compiling it yourself, the only other option is to thin out
> > > the httpd executable so that it is only i386.
>
> > > This can be done by the following procedure. Be very careful in doing
> > > this as you are modifying OS files. Only do it if you are really
> > > desperate and keep backups.
>
> > > cd /usr/sbin
>
> > > sudo mv ./httpd ./httpd.fat
> > > sudo lipo ./httpd.fat -thin i386 -output ./httpd.i386
> > > sudo ln -s ./httpd.i386 ./httpd
>
> > > After doing that, you should end up with:
>
> > > $ file ./httpd.fat
> > > ./httpd.fat: Mach-Ouniversalbinary with 4 architectures
> > > ./httpd.fat (forarchitectureppc7400): Mach-O executable ppc
> > > ./httpd.fat (forarchitectureppc64): Mach-O 64-bit executable ppc64
> > > ./httpd.fat (forarchitecturei386): Mach-O executable i386
> > > ./httpd.fat (forarchitecturex86_64): Mach-O 64-bit executable x86_64
> > > > > > libmysqlclient_r.a (forarchitectureppc): current ar archive
>
> > > > > > So that means that in order to link to the MySQL libs, we'll need to
> > > > > > build/install a 64-bit version of MySQL. Sigh...
>
> > > > > > Anyone have a set of reliable, working instructions for doing that?
>
> > > > > > -Ben
>
> > > > > > On Oct 30, 7:11 pm, "bmitch...@gmail.com" <bmitch...@gmail.com> wrote:
>
> > > > > > > Stuck in the same place.
>
> > > > > > > I'm guessing you d/l'd and installed the MySQL OSX 10.4 x86 installer
> > > > > > > package from MySQL. I did. I think it's only i386.
>
> > > > > > > They also have aUniversalBinary OSX 10.4 file up there, but only in
Reply all
Reply to author
Forward
0 new messages