2012年10月1日星期一

Set up Django, Python, MySQL-db

For MAC OS snowleopard, it is really a headache on resolving django, python MySQL-python, MySQL, and make them work.

I resolved the issue using the reference:
http://stackoverflow.com/questions/4730787/python-import-mysqldb-error-mac-10-6

It would be better to use 3rd party tools such as MacPorts to get these tools, I did:
sudo port install py26-mysql
sudo port install py26-django

After that, we need to set the default python to the version that macports downloaded. The location would be /opt/local/bin/python2.7.

The default python would be /usr/bin/python.

In order to create a symlink from /usr/bin/python to /opt/local/bin/python2.7, we need to do the following:
http://stackoverflow.com/questions/6943812/macports-select-default-python-interpreter-for-executing-scripts


mv /usr/bin/python /usr/bin/python.orig
ln -s /opt/local/bin/python /usr/bin/python
port select --set python python26


We may encounter errors:
Selecting 'python26' for 'python' failed: symlink: /opt/local/etc/select/python/current -> python26: file already exists
Way to resolve this is to go to the /opt/local/etc/select/python/ directory, and do 'mv current wasCurrent', then redo the 3rd step of port select

After that, we have updated the default python to the port macports installed, and we have django installed also. We could do:


Python 2.6.8 (unknown, Apr 14 2012, 04:15:37)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> import MySQLdb
>>>



to test whether we have made them successfully installed.


没有评论:

发表评论