Like many of Apple fanboys out there even I decided to upgrade Mac OS X Snow Leopard (10.6) to Mac OS X Lion (10.7) as soon as it was made available on App Store. Upgrading from App Store was pretty smooth and was surprised it did not break any apps (May be that’s because it’s just an incremental upgrade with some fancy features) except my Django projects failing to validate because of the default python version change (from 2.6.x to 2.7.1) and can be easily fixed. However I decided to go for fresh install of OS X Lion to test how fresh install (wipe out disk after backup and install ) works with OS X Lion.
Once done with fresh installation of Mac OS X Lion, immediate task was setting up my development environment which includes MySQL server, phpMyAdmin and Django.
Steps I followed to get Django development environment back are as below
- Install Xcode via Mac OS X App Store ( Might be required when you compile and install from source)
- Install MySQL Server
- Install phpMyAdmin
- By default jpeg, freetype, littlecms image library support is missing, you need to install at least jpeg support so ImageField in your django project supports jpeg formats.
- Install JPEG libraries
- Download JPEG library source curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
- Extract tar -xvzf jpegsrc.v8c.tar.gz
- Switch to jpeg directory cd jpeg-8c
- Run ./confgure
- Run make
- Run sudo make install
- Install Freetype libraries
- Download Freetype library source curl -O http://ftp.igh.cnrs.fr/pub/nongnu/freetype/freetype-2.4.5.tar.gz
- Extract tar -xvzf freetype-2.4.5.tar.gz
- Switch to freetype directory cd freetype-2.4.5
- Run ./configure
- Run make
- Run sudo make install
- Install Django using sudo easy_install django
- Install Python Image Library (PIL) using sudo easy_install PIL
- Install mysql-python driver using sudo easy_install MySQL-python (Make sure you got mysql in your PATH, otherwise this will fail with mysql_config not found error)
That’s all you need to go ahead and start creating Django projects. However I prefer using virtualenv for all my Python projects. If you take this route, you can use pip install <package_name> to install necessary packages for example pip install django, pip install MySQL-python, pip install PIL to install Django, MySQL Python driver and Python Image Library.
Update 1 (25/07/2011): If you get error “django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/_mysql.so
Reason: image not found”, when you validate your project or try to use MySQL-python,
Type export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/” in your terminal and see if problem persists. You can add it to your .profile file to make this persistent so you don’t need to run it every time.
Thanks! Thanks! Thanks!
Im have a really tough week so far because of Lion, nothing that a fresh install and this tutoria doesn’t resolve.
Pingback: Installing Django on Snow Leopard (and MySQL and PIL)
Hi
I get the error:
File “/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py”, line 14, in
raise ImproperlyConfigured(“Error loading MySQLdb module: %s” % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/torsten/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): no suitable image found. Did find:
/Users/torsten/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture
I tried to export the path but it didn’t help. Do you have any idea ?
Thanks
why not using virtualenv? It makes installing really easy.
My config file in bin not lib and had to put it in my /private/etc/bachrc file like this:
export PATH=/usr/local/bin:/usr/local/mysql/bin/:$PATH
Then python-mysql installed ok.
@torsten if you copy and paste that additional export path line, make sure to change the quotation marks to normal ones…also make sure you installed the 64 bit version of mysql server.
Thank you for putting this tip out there, it solved the problem finally!
Great tutorial! Much easier than anything else I can find (and it worked). The only issue I am having, I still have to add this line (export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/”) to the terminal each time. I have tried to add it to the .profile (nano ~/.profile) but without success. Although this line works, my mysql_config, is in /usr/local/mysql/bin? Any advice?
Update: Just go it working. Added export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/” to bash_profile (nano ~/.bash_profile)!
I did all this, but when i import PIL, it says ” from PIL import Image
ImportError: No module named PIL”
and when i try to install PIL via easy_install it says
“Processing PIL-1.1.7-py2.7-macosx-10.7-intel.egg
PIL 1.1.7 is already the active version in easy-install.pth”
Getting this error on sudo easy_install PIL
unable to execute llvm-gcc-4.2: No such file or directory
error: Setup script exited with error: command ‘llvm-gcc-4.2′ failed with exit status 1
Do you have xcode installed ?
The quotes in the update 1 export command don’t work in properly in the command but once I replaced them with normal quotes it worked fine.
export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/”
i am using Macbook Pro with Lion installed and i also installed the apple latest development toolkit .
I tried to install the JPEG but i stuck with one problem.
When i typed the commond
./configure
I have following output
#########
checking build system type… x86_64-apple-darwin11.2.0
checking host system type… x86_64-apple-darwin11.2.0
checking target system type… x86_64-apple-darwin11.2.0
checking for a BSD-compatible install… ./install-sh -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… ./install-sh -c -d
checking for gawk… no
checking for mawk… no
checking for nawk… no
checking for awk… awk
checking whether make sets $(MAKE)… yes
checking for style of include used by make… GNU
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking dependency style of gcc… none
checking for function prototypes… yes
checking how to run the C preprocessor…
#########
after that it runs for long tie and it seems t be that it stuck on
<>
there is no output or message. Do you have any idea why it is so?
any suggestion to solve this problem will be highly appreciated.
Regards
I have XCode4 installed and I get the
> error: Setup script exited with error: command ‘gcc-4.2′ failed with exit status 1
Any ideas?
I have Xcode installed, have sym linked to mysql_config, but when I run `python setup.py install` I get a flood of errors like this:
‘_mysql_ConnectionObject’ has no member named ‘open’
or
‘_mysql_ConnectionObject’ has no member named ‘connection’
Then, it prints this error:
lipo: can’t open input file: /var/tmp//ccEHQ50W.out (No such file or directory)
Which makes sense, because of the double slash (not sure how to resolve that, however)
And finally, the standard closing error of:
error: Setup script exited with error: command ‘llvm-gcc-4.2′ failed with exit status 1
You might be able to save yourself some effort with the freetype/PIL installation by using Pillow instead. Check out http://www.cmlenz.net/archives/2011/07/building-pil-with-freetype2-on-snow-leopard
I’d really recommend you look at a couple of things that will make your life a whole lot easier. #1 is homebrew. It makes installing unixy stuff much, much easier on Mac OS X. `brew install foo` is almost always enough to get what you want.
The other, as mentioned above is virtualenv. If you don’t develop with virtualenv, then you make your life a whole lot harder. I even deploy to a virtualenv on production servers. It makes everything else installable without root requirements.
Then, once you are doing that, look into fabric as a deployment solution. When you are able to deploy with a single command (`fab deploy –host servername`) it suddenly becomes simple to deploy.
(Alternatively, look at heroku for a single-command deployment and hosting solution).
Other random thoughts: you really should use Postgres instead of MySQL (for lots of reasons), and if you aren’t using SCM of some sort, even if it’s svn, then STOP WHAT YOU ARE DOING NOW AND START USING SOMETHING. It really is that important.
+1 for using homebrew. It may seem more complicated initially, but will save you a ton of time going forward developing on a Mac.