views:

1609

answers:

6

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tell me where I need to start and what steps I need to follew I would be most grateful.

Thanks

+1  A: 

First and foremost, make sure that XCode is installed. Without XCode, many pieces of the built-in Apache2 server important to developers are missing; most notably, the GNU Compiler Collection, which I would think to be requisite for MySQL bindings.

cpharmston
Xcode is install the newest version that came on the snow leopard disc I also install the 10.4 SDK like someone else suggested. Any more tipe?
sico87
+2  A: 

[Partial Answer]

You'll have more fun pulling out your teeth. MySQL/Django/Mac is a disaster. This is the farthest I've gotten:

Get MySQLDB 1.2.3 Go into that and modify setup_posix.py:

Change:

mysql_config.path = "mysql_config"

To (depending on the version number of your MySQL):

mysql_config.path = "/usr/local/mysql-5.1.34-osx10.5-x86_64/bin/mysql_config"

python setup.py build python setup.py install

Here's a good article

Adam Nelson
+2  A: 

I'd recomend installing macports (latest svn trunk) and installing mysql from there.

sudo port install mysql5-server

Download the MySQL-python-1.2.2 source

make sure /opt/local/lib/mysql5/bin is in your path or edit site.cfg to include:

mysql_config = /opt/local/lib/mysql5/bin/mysql_config

Comment out line 38 of _mysql.c

// #define uint unsigned int

Then run:

sudo python setup.py install

should be all good.

sleepyjames
To add it to your path, edit `~/.profile`, add `export PATH=$PATH:/opt/local/lib/mysql5/bin` to the end, and run `source ~/.profile`. To verify: `echo $PATH`
Cawas
A: 

That's not possible :

Comment out line 38 of _mysql.c

// #define uint unsigned in

as it's not in the file (latest version).

Any other suggestion? Im struggling with that problem! Tried many tutorial without success. Thanks for any info!

Rom
A: 

1) Xcode was installed.

2) Follow these instructions for setting up apache/php/mysql:

http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

3) I installed the free 32-bit version of EPD (this is optional but I wanted numpy/scipy).

4) Make sure you have these lines in your ~/.profile (the second line is only if you installed EPD):

export PATH=/usr/local/mysql/bin/:/usr/local/bin:/usr/local/sbin:$PATH export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"

5) Downloaded mysqldb and run:

python setup.py build

sudo python setup.py install

6) Install the official release of Django or web2py. Everything worked after that. You can try the "Writing Your First Django App, Part 1" to test it out where in settings.py use:

DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'Django Polls'
DATABASE_USER = '*'
DATABASE_PASSWORD = '*'
DATABASE_HOST = '127.0.0.1'
DATABASE_PORT = '3306'

7) I also use Navicat Lite and Sequel Pro for working with MySQL.

8) Pydev is a nice IDE to use with Django.

David Dreisigmeyer
The '*' should be DATABASE_USER = 'your_db_user_name'DATABASE_PASSWORD = 'your_db_password'
David Dreisigmeyer
A: 
  1. Install the newest 64bit DMG version of MySQL. Remember to backup your databases if you already have MySQL installed.
  2. enter this line in terminal:

    sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

  3. Edit the file setup_posix in the mysql-python installation directory.

Change the line

mysql_config.path = "mysql_config"

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"
  1. Myslq-Python needs a 64bit Version of Python. The new Python 2.7 64bit version creates an alias in /usr/local/bin/python.
  2. Enter the following lines in the mysql-python folder:

sudo /usr/local/bin/python setup.py clean sudo ARCHFLAGS="-arch x86_64" /usr/local/bin/python setup.py build sudo /usr/local/bin/python setup.py install

And finally try it out:

python
import MySQLdb
sbaechler