# Installing and setting up OS X Mavericks for python development (WIP)

A clean OS X Mavericks install for Python and Django development — case-sensitive filesystem, ZSH, Homebrew, PostgreSQL, virtualenv, PyCharm, and the rest of the stack.

Published: 2013-10-23
Source: https://www.kristian.io/django/2013/10/23/setting-up-os-x-mavericks-for-python-development.html/

While this is not required, I have chosen to re-install my mac from scratch with the new OS X Mavericks. This gave me the opportunity to correct a few less smart decisions i took previously. Here I'll describe the process it took for me, to get OS X Mavericks properly running - skip the reinstall part, if you just want to upgrade using the App Store.

**Make sure you have a backup before attempting to install OS X Mavericks. I use time machine, but you can use whatever you are comfortable with. Make sure the backup is not connected to your Mac, until everything works.**

*I'm updating this article as I get feedback and discover missing libraries etc.*

Creating a bootable USB disk
----------------------------------------
*Credits to http://forums.macrumors.com/showpost.php?p=18081307&postcount=3*

1. Insert USB disk to your mac, make sure no other devices are connected
2. Open Disk Utility
3. Format your USB disk to Mac OS X Extended (Journaled) and make sure it's called "Untitled"
4. Run the following command (takes 20-30 min):

```bash
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
```

5. Now you can boot from your new USB disk by pressing the option key (alt) - but keep on reading, before you continue the installation!

File system
----------------
I have chosen to re-format my OS X disk as a case sensitive file system. I'd recommend you to do the same if you deploy your code on case-sensitive systems, such as most linux distributions.

When you boot from the USB you should be presented with the option of installing OS X and Disk Utility (and a few other options). Press Disk Utility and Continue. Now select your partition and go to the Erase tab. Select "Mac OS Extended (Case-sensitive, Journaled) and press Erase. **This will remove all data from your disk, so please do make sure that you have backup.**

**Caution: Some applications might not work with case sensitive file systems.**

Installing OS X
--------------------
This is pretty straight forward. However, when the installation says "A few seconds remaining", it seems to be a common issue that it takes around 20-30 min to complete.

Furthermore, after initially installing OS X it rebooted and started the installation over again. The 2nd time everything worked.

Enabling apps from everywhere
-----------------------------
Under Security and Privacy set "Allow apps downloaded from" to "Anywhere"

~~Terminal~~
---------
~~You don't want to be stuck with the default terminal in OS X. [iTerm 2](http://www.iterm2.com/) offers a great alternative with more configuration options *and more colors*.~~

I recommend the [solarized](http://ethanschoonover.com/solarized) theme - but I guess thats a question of personal taste. Solarized is available for a few other tools as well.

[@keleshev](https://twitter.com/keleshev) just told me that Terminal.app indeed supports 256 colors, which I just confirmed in my terminal. AFAIK no more reason to use iTerm 2 ;)
Oh My ZSH
----------------
I have previously written about the [tools I use](http://blog.kristian.io/post/46338461184/how-i-develop-django-projects/) when developing django. I warmly recommend [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh), which is super easy to install: 

```bash
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
```

On my Github you can find some of the [scripts I use](https://github.com/KristianOellegaard/zsh-plugins). I have many others, if you are interested, ping me on [twitter](https://twitter.com/oellegaard).

Homebrew
--------------
*Homebrew installs the stuff you need that Apple didn’t.*

Homebrew helps you compile different kinds of software on your mac, making it feel almost as easy as apt-get'ing a package on e.g. ubuntu. You can install it like this:

```bash
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
```

More info at [brew.sh](http://brew.sh)

PostgreSQL
-----------------
Homebrew makes it a breeze to install PostgreSQL on OS X.

```bash
brew install postgresql
```

To make it auto start on login, you have to run

```bash
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
```

If you don't use it a lot, there is also the possibility to use [PostgreSQL.app](http://postgresapp.com), however for my own use i prefer the homebrew  version.

Opera Next
---------------
This is an area with a lot of politics in it, so I will just tell you why I use Opera Next and then you can go ahead and install whatever you want.

I'm not a big fan of Google and I'm trying to move away from most of their services, so I was happy when Opera announced they wanted to move to webkit, even the chrome fork. I feel better using a browser from a company, that doesn't get its income from selling my personal information. Other than that, it feels much like chrome. Be sure to get [Opera Next](http://www.opera.com/computer/next), though. The regular Opera is a bit behind in terms of features.

Vim
-----

I use vim quite a lot. I prefer using it, over some more heavy IDE's for simple configuration file edits and some times very small python scripts. I use the following plugins. OS X comes with vim, so the only thing I did was to add a few plugins:

- gundo
- nerdtree
- powerline
- python-mode
- tagbar
- vim-fugitive
- vim-puppet
- vim-sensible


PyCharm
-------

Now available in a free community version as well, [PyCharm](http://www.jetbrains.com/pycharm/) is the best IDE around if you ask me. Previously they were also known to provide licenses to core contributors in open source projects, if requested.

PyCharm integrates with virtualenv and pip and is aware of several frameworks. If you work with Django, you'll be happy to know it support Django templates, even jump to definition inside templates! PyCharm is provided as a dmg file, so it's a super easy install on OS X. On initial launch it will ask you to install Java RE, which you won't have available on a clean Mavericks install. 


Python stuff
----------------
First, let's get pip!

```bash
sudo easy_install pip
```

Now, virtualenv. If you don't know virtualenv, I suggest you read my previous post about [developing django projects](http://blog.kristian.io/post/46338461184/how-i-develop-django-projects/) (it also applies to many other frameworks).

```bash
sudo pip install virtualenv
```

If you use gevent, you are going to need libevent, which is fortunately only one command away:

```bash
brew install libevent
```

That's it.
----------

```bash
mkdir tmp
cd tmp
virtualenv .
source bin/activate
pip install Django
django-admin.py startproject helloworld
python helloworld/manage.py runserver
```

One last thing
--------------

Get *lock screen* working on your Mac. Open Keychain Access. Go to Preferences and select "Show Keychain status in menu bar".

If you liked the article, you can follow me on [twitter](https://twitter.com/oellegaard). I'll be more than happy to reply to any questions there or you can join the [discussion on hacker news](https://news.ycombinator.com/item?id=6610764).
