I setup Python and Django using homebrew the easy way. I am going to detail the process now.
Install Python
1 |
brew install python |
The command should first install any dependencies for Python and then install the latest version from source code.
Adding Python to PATH
We need to edit our ~/.bash_profile to add “/usr/local/share/python” to the path variable. I added the following line to my bash profile:
1 |
export PATH=/usr/local/share/python:$PATH |
I reloaded the profile by issuing:
1 |
source ~/.bash_profile |
This makes the python tools and toys accessible from my terminal.
Install MySQL Module
It’s recommended that you already have “mysql” installed from brew to build the mysql module. I already had it installed so it was a painless installation for me. I just issued the command:
1 |
pip install mysql-python |
Install Django
I am going to keep using the PIP awesomeness! Let’s hit:
1 |
pip install django |
It will install django with any dependencies. You can now invoke the “django-admin.py” command from your terminal. However, I prefer the command be “django-admin”, instead of “django-admin.py”. So I created the following alias in my ~/.bash_profile:
1 2 |
#Django alias django-admin=/usr/local/share/python/django-admin.py |
Isn’t it simple? 😀
4 replies on “Setting up Python, MySQL Module and Django on Mac OS X Lion”
OS X comes with python. Why do you need it to be installed again?
Vaiya, because I wanted to install the latest version and keep my development environment separate!
Dear brother,
I can’t install mysql-python. I installed before. Last one month ago i had to send my mac for reinstall. Any way I have the following application-
MySQL – 5.6.11 ( Download .dmg from mysql official site
Python – 2.7.2 ( By default install)
pip list:
altgraph (0.9)
argparse (1.2.1)
bdist-mpkg (0.4.4)
bonjour-py (0.3)
Django (1.6.5)
djangotoolbox (1.6.2)
gntp (1.0.2)
macholib (1.4.2)
modulegraph (0.9.1)
mongoengine (0.8.7)
numpy (1.6.1)
pip (1.5.6)
py2app (0.6.3)
pymongo (2.7.1)
pyOpenSSL (0.13)
PyRSS2Gen (1.0.0)
python-dateutil (1.5)
setuptools (5.1)
simplejson (3.5.2)
Twisted (12.0.0)
virtualenv (1.11.6)
wsgiref (0.1.2)
xattr (0.6.2)
zope.interface (3.5.1)
So when I tried to install mysql-python, i got different type of error. I tried to install from source file version 1.2.2, 1.2.3, 1.2.5 etc.
I tried to install brew command.
Brew Command Error:Â
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/private/tmp/pip_build_root/mysql-python/setup.py) egg_info for package mysql-python
sh: mysql_config: command not found
Traceback (most recent call last):
File “<string>”, line 17, in <module>
File “/private/tmp/pip_build_root/mysql-python/setup.py”, line 17, in <module>
metadata, options = get_config()
File “setup_posix.py”, line 43, in get_config
libs = mysql_config(“libs_r”)
File “setup_posix.py”, line 25, in mysql_config
raise EnvironmentError(“%s not found” % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File “<string>”, line 17, in <module>
File “/private/tmp/pip_build_root/mysql-python/setup.py”, line 17, in <module>
metadata, options = get_config()
File “setup_posix.py”, line 43, in get_config
libs = mysql_config(“libs_r”)
File “setup_posix.py”, line 25, in mysql_config
raise EnvironmentError(“%s not found” % (mysql_config.path,))
EnvironmentError: mysql_config not found
—————————————-
Cleaning up…
Command python setup.py egg_info failed with error code 1 in /private/tmp/pip_build_root/mysql-python
Storing debug log for failure in /Users/macbook/Library/Logs/pip.log
Manually Installation Error: (mysql-python 1.2.3)
MacBooks-MacBook-Pro:MySQL-python-1.2.3 macbook$ sudo python setup.py install
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
/usr/bin/python -E -c pass
TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file ‘MySQL_python.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
warning: no files found matching ‘MANIFEST’
warning: no files found matching ‘ChangeLog’
warning: no files found matching ‘GPL’
writing manifest file ‘MySQL_python.egg-info/SOURCES.txt’
installing library code to build/bdist.macosx-10.8-intel/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
running build_ext
building ‘_mysql’ extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.8-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing -arch x86_64
clang: error: unknown argument: ‘-mno-fused-madd’ [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command ‘clang’ failed with exit status 1
Installing MySQL through brew (even if you don’t use the brew version later) would probably solve it. mysql-python package requires the mysql_config command available on $PATH. You can also find this command (it’s on your mysql bin directory) and manually add to path.