views:

40

answers:

3

Hi,

I've tried to solve this myself searching and searching but I can't get it to work. :( I'm in Snow Leopard 10.6.4 and tried to setup my Django environment, first I upgraded my python to 2.6.5, installed django and then mysql_python. All seems to be smooth until I to connect to mysql using syncdb.

Got this error/trace message: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I've tried following the solution provided http://forums.mysql.com/read.php?50,282410,286676 but still the same. I believe it has something to do with my python version because when I execute /usr/bin/python it returns Python 2.6.1 but when I just typed python it says 'Python 2.6.5 '.

Anyone? I think when I build and install mysql_python using the ARCHFLAGS="-arch x86_64" /usr/bin/python setup.py build command its using the default django version (2.6.1) on SL and not the new one (2.6.5).

Anychance I can get this to work with 2.6.5? Thanks.

A: 

type:

which python

figure out where it is pulling python 2.6.5 (which is not the current python as distributed by Apple). You might be able to symlink /usr/bin/python to your 2.6.5 installation, but, that just seems like you're asking for trouble.

You could install your mysqldb within your virtual environment which would put it in the right place. I'm guessing you installed python from a .dmg or source but it didn't completely install, or, didn't overwrite the Apple provided version on purpose.

user6738237482
A: 

You may be using either Python version depending on what's the value of the PATH environment variable at the time you're invoking Python. It's important that Apple's own Python remains in the system in /usr/bin since it's used by some other parts of the operating system and you don't want to risk breaking those, so your alternative Python is most likely installed in /usr/local/bin (unless you used Darwinports or the like to install it, in which case it will be somewhere under /opt).

You can install extensions under either or both versions of Python -- if you're using a normal python setup.py install terminal command for the installation, the add-on will be installed for the version of python that you're running setup.py with, for example. Simplest might be to install on both (or use virtualenv as the other answer suggests) -- all that takes is two commands, /usr/bin/python setup.py install for the system version and (if your add-on version is in /usr/local/bin) /usr/local/bin/python setup.py install. (Either or both might need to be prefixed by sudo depending on how you set up permissions and ownerships for the various directories involved).

Alex Martelli
A: 

First thanks for the answers! :) Made me think and helped me sort things out.

So what I did was to determine what architecture my python 2.6.5 shell is running. Got this http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode and found out that it is running in 32bit. I must be the sole reason why mysql python won't work because I've got the 64bit mysql installed.

I then deleted mysql on /usr/local and applied this handy little tip http://egopoly.com/2009/09/01/how-to-uninstall-mysql-5-1-on-snow-leopard/ just to make sure the 32bit mysql installer won't complain.

I downloaded mysql_python] again and edited line 26 on setup_posix.py file from mysql_config.path = "mysql_config"to mysql_config.path = "/usr/local/mysql-5.1.48-osx10.6-x86/bin/mysql_config"and then executed the following commandspython setup.py build and sudo python setup.py install

And then voila! :D it's working! Now I can sleep. Again thanks for the help!

voidnothings