Skip to main content

Django: Instalation of Dev environment on a clear Lion Mac OS X

Like lots of Apple fans around the world I've finally decided to upgrade my OS to Lion release. I have bought a new laptop and it was the case. I've waited for a weekend to prepared myself for sex. And it was it. Now I want to share my experience with you guys. For you not to spend to much time on those issues, I've did.

Anyway what I'm usually using is a Fresh 2.7 Python, Django, PIL, virtualenv and many many minor tools which exceed scopes of this article. I also use Eclipse IDE for Python Dev. So all this I had to install and make spinning till monday.

If anybody tells me that Macs do not have good tools for this. He will not be right. Maybe there some itches and scratches of head about:
"Why is not those things working" or "Why do they work not as preferred". But there always is a good "Googled" decision to handle that.
Anyway lets go to installing stuff.

Short brief Plan of out work:
1. Install Apple Development SDK + Xcode (free from Apple App Store).
2. Install Python (from python.org/getit).
3. Install Libraries needed for PIL (Libjpeg and Freetype support).
4. Install Django.

1. First of all! Mother of all Gods! We need Xcode and Mac Development tools provided from AppStore for Free. Let's download it and install it. If you have an apple store Account, of course. Actually here we do not need the whole bunch of stuff like Xcode or Dev tools except for GCC. And if you're advanced enough and have time to handle it... You should probably just install GCC, compiling it from sources for e.g. I'm not gonna spend time at those "low levels" and will simply install a set of packages that I may (or may not) need in future for dev.

After Xcode is Downloaded you should go to Applications of Lunchpad and hit Xcode icon. (They are actually only downloaded not installed yet. What a long time period,  waiting for 1,6 Gigs App download form App Store.) Hit 'next', 'yes' and so on... Agree to everything and probably close some apps like for e.g. iTunes somewhat weirdly but true. Anyway lets continue to our next and main part. Those actions should already give us required GCC compiler for all our needs.

2. Next step is installing Python. We should get it from here, for e.g.: http://python.org/getit/. I've chosen Python 2.7.2 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and 10.7). It gave latest stable 2.7.2 Python with idle for about 17 Mb more downloading.
DMG file has a simple enough installer that will ask you for root password and do all the stuff you need for you...

3. Support of jpeg, freetype and littlecms is missing, by default. You need to compile PIL with support of at least jpeg and freetype. In order to make ImageField in your django project support jpeg formats and Have ability to handle Captcha fields or different text with picture manipulations.
You may need to switch to 'sh' interpreter from standart 'bash' typing sh in command line. It handles ./congure and make install commends more gracefully (IMHO). And you may need 'sudo' to gain permissions to some system stuff here.
Will try to be brief here:
  • Install JPEG support 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 (I only made it work at 'sh' command prompt someway)
    • Run make
    • Run sudo make install
  •  Install Freetype support:
    • 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
    • Enter to freetype directory cd freetype-2.4.5
    • Run ./confgure (I only made it work at 'sh' command prompt someway)
    • Run make
    • Run sudo make install
  • Actually install PIL:
    • Type: sudo easy_install PIL
    • End!
Now PIL Should compile with support of FreeType Fonts and LibJpeg. I also used easy_install pip first. Because I simply like PIP more and it's much less to type pip install. But it's a matter of taste... Anyway we must see something like this after PIL installs:

This will indicate successful installation of PIL and components.

4. Installing Django is easy now. Jut do it whatever way you prefer. Like sudo pip install django or
sudo easy_install django or even sudo pip install django==1.1, if you prefer oldies. :)

I prefer to use virtualenv 'your virtual env name here' --no-site-packages for every app of mine... So I'm not even installing Django to main system path as well... Btw if you've used virtualenv with you projects, like I did, prepare yourself.  They need to be recreated. So be sure to save them with pip freeze. Maybe they will work if you pu them back to the same system path as they where... But there might be daemons here :).


I'll try to cover installation of MySQL environment on a "clean" Lion install in my next articles.

Anyway if you've found this article useful or think that I'm not right somewhere or even something less important... Feel free to drop me a comment here or contact me any available way.  Thanks for reading so far and hope this will shorten your time while installing some things.



Comments

Popular posts from this blog

Pretty git Log

SO you dislike git log output in console like me and do not use it... Because it looks like so: How about this one? It's quite easy... Just type: git log - - graph - - pretty = format : '%Cred%h%Creset -%C ( yellow ) %d%Creset %s %Cgreen ( %cr) %C ( bold blue ) <%an>%Creset' - - abbrev - commit - - It may be hard to enter such an easy command every time. Let's make an alias instead... Copypaste this to your terminal: git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --" And use simple command to see this pretty log instead: git lg Now in case you want to see lines that changed use: git lg - p In order for this command to work remove  the -- from the end of the alias. May the code be with you! NOTE: this article is a rewritten copy of  http://coderwall.com/p/euwpig?i=3&p=1&t=git   and have b...

Django: Resetting Passwords (with internal tools)

I have had a task recently. It was about adding a forms/mechanism for resetting a password in our Django based project. We have had our own registration system ongoing... It's a corporate sector project. So you can not go and register yourself. Admins (probably via LDAP sync) will register your email/login in system. So you have to go there and only set yourself a password. For security reasons you can not register. One word. First I've tried to find standart decision. From reviewed by me were: django-registration and django password-reset . These are nice tools to install and give it a go. But I've needed a more complex decision. And the idea was that own bicycle is always better. So I've thought of django admin and that it has all the things you need to do this yourself in no time. (Actually it's django.contrib.auth part of django, but used out of the box in Admin UI) You can find views you need for this in there. they are: password_reset password_reset_...

Vagrant error: * Unknown configuration section 'hostmanager'.

Sometimes you get a vagrant environment or boilerplate with a Vagrantfile config in there and do a vagrant up command. And see some errors. like this: There are errors in the configuration of this machine . Please fix the following errors and try again : Vagrant: * Unknown configuration section 'hostmanager'. To fix this one needs: $ vagrant plugin install vagrant - hostmanager Installing the ' vagrant-hostmanager ' plugin . This can take a few minutes . . . Fetching : vagrant - hostmanager - 1.8 .6 . gem ( 100 % ) Installed the plugin ' vagrant-hostmanager (1.8.6) ' ! So command to fix this as follows: vagrant plugin install vagrant-hostmanager