Skip to content

Instantly share code, notes, and snippets.

@nabucosound
Last active February 4, 2017 22:49
Show Gist options
  • Save nabucosound/1551472 to your computer and use it in GitHub Desktop.
Save nabucosound/1551472 to your computer and use it in GitHub Desktop.
This is a personal HOW-TO I have been using lately to install and setup my Macbook Pro laptop with OS X, to be used as a developer machine for Python, Django, MySQL and other tools I use daily for my projects.

Mac OS X for a Python developer

This is a personal HOW-TO I have been using lately to install and setup my Macbook Pro laptop with OS X, to be used as a developer machine for Python, Django, MySQL and other tools I use daily for my projects. To get most of the software Homebrew is been used.

Terminal

Install a better font:

http://www.silassewell.com/blog/2007/11/18/better-terminal-font-os-x-gnome/

To avoid garbled prompt when connecting to Ubuntu via ssh, edit settings for desired profile > Emulation > Declare terminal as xterm.

Generate SSH public key and add it to a server:

ssh-keygen
scp .ssh/id_rsa.pub user@domain.com:/home/user/
ssh user@domain.com
cat /home/user/id_rsa.pub >> .ssh/authorized_keys

Edit /etc/ssh_config` and add the following directive to make ssh send keepalive requests to the server, avoiding NAT firewalls to close idle connections:

Host *
   ServerAliveInterval 300

Homebrew and Git

Follow doc to install homebrew from github (note that the URL that curl is using on this example will probably be out-of-date:

https://github.com/mxcl/homebrew/wiki/installation

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install git
brew update
brew upgrade

Set your username and email (replace github_username with your own) and vim as your default editor:

git config --global user.github_username "Name Surname"
git config --global user.email "your@email.com"
git config --global core.editor /usr/bin/vim

Set colors for Git output (useful mostly for git diff):

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Python

Install Homebrew python:

brew install python

Edit .bash_profile to add /usr/local/ paths before system ones:

# Homebrew binaries and scripts before system ones (e.g. python)
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/share/python:$PATH

Install pip and append bash completion to your .bash_profile:

easy_install pip
pip completion --bash >> ~/.bash_profile

Install virtualenv and virtualenvwrapper:

pip install virtualenv virtualenvwrapper

Add virtualenwrapper env variable and .sh to your .bash_profile:

# Virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/share/python/virtualenvwrapper.sh

Install libjpeg for JPEG support (e.g. python PIL):

brew install libjpeg

Install ICU (proper Unicode sorting on python strings, unsing pyicu binding library):

mkdir /usr/local/src/
cd /usr/local/src/
curl -O http://download.icu-project.org/files/icu4c/4.8.1.1/icu4c-4_8_1_1-src.tgz
tar xvzf icu4c-4_8_1_1-src.tgz
cd icu/source
./runConfigureICU MacOSX --with-library-bits=64 --disable-samples --enable-static
make && make install

Vim

OS X Lion does not come with Vim compiled with python, so we use the one that provides MacVim on Homebrew:

brew install macvim

Edit your .bash_profile to add the following:

vim='/usr/local/Cellar/macvim/7.3-63/MacVim.app/Contents/MacOS/Vim -n'
alias vim="${vim}"

Install pathogen plugin manager:

mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -so ~/.vim/autoload/pathogen.vim \
    https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim

Create your .vimrc with the minimal conf to run pathogen and set python syntax rules for editing files:

" Pathogen load
filetype off

call pathogen#infect()
call pathogen#helptags()

filetype plugin indent on
syntax on

let python_highlight_all=1
set tabstop=4
set shiftwidth=4
set expandtab
set encoding=utf-8
set autoindent

" Status line
set laststatus=2
set statusline=%t\ %y\ format:\ %{&ff};\ [%l,%c]

Install your Vim plugins:

cd .vim/bundle/
git clone https://github.com/mitechie/pyflakes-pathogen.git
git clone https://github.com/fholgado/minibufexpl.vim.git
git://git.wincent.com/command-t.git

Troubleshooting:

https://coderwall.com/p/dhftbw

RabbitMQ

Install RabbitMQ:

brew install rabbitmq

Tasks are managed by Celery with a RabbitMQ broker. First run the detached (daemon) RabbitMQ server:

rabbitmq-server -detached

If you want to get the mochiweb running to manage queues and so:

rabbitmq-plugins enable rabbitmq_management
rabbitmqctl stop
rabbitmq-server -detached

Then visit http://localhost:55672/mgmt/ with guest and guest.

Whenever you want to empty/purge queued messages on RabbitMQ, use:

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app

MySQL

Install MySQL:

brew install mysql

To stop and start the service:

mysql.server stop
mysql.server start

Troubleshooting

MySQL may give a MySQL server has gone away error while trying to generate newsletters with the generate_newsletter Dealirius django custom command. This is caused by the size of data of the base64 encoded message data of the Message model on the django-mailer side. It can be solved easily editing the MySQL my.cnf and increasing the value of max_allowed_packet setting to more Megabytes.

On Mac OS X installations using homebrew, we must create a new my.cnf using one of the samples provided. Copy the file, edit it, and do not forget to restart the service:

sudo cp $(brew --prefix mysql)/support-files/my-small.cnf /etc/my.cnf
mysql.server restart

Other

Install Solr:

brew install solr

The GeoIP C API is used by Django GeoIP. Dealirius instances try to get the user's city automatically using their IP:

brew install geoip

Install Mercurial for pip requirements repositories using it:

brew install mercurial

Install Image Magick to do operations like checking dimensions or resizing:

brew install imagemagick

Install Gettext to create translation files for developments like Django:

brew install gettext
brew link gettext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment