Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setting Up OSX For Python Developments

Setting Up OSX For Python Developments

This gist has been created using OSX Mavericks, but it sould work with any OSX 64-bits system – Mountain Lion, Mavericks and for sure Yosemite ;) In case that you are using a OSX 32-bits system OSX Lion or Snow Leopard (OSX Leopard is not supported by XCode) just include the 32-bits System? section.

Bash profile setup

64-bits System

OS X Mountain Lion, Mavericks & Yosemite are full 64-bit systems so lets configure them to ensure that incoming user's package installations (e.g., Homebrew package installations) will be on a 64 bits system and taking precedence over OSX packaged binaries.

  • Create or edit a bash profile file, vim ~/.bash_profile and include the following

64 bits user's package installations

export ARCHFLAGS="-arch x86_64"

User's binaries

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Load .bashrc if it exists

test -f ~/.bashrc && source ~/.bashrc

- Re-load the bash environment configuration `. ~/.bash_profile`

### 32-bits System?

In case that are you using a **OSX 32-bits system** OSX Lion or Snow Leopard (OSX Leopard is not supported by **XCode** which is **required** for `Homebrew` installation)...

- **Remove the lines** related with 64 bits `bash_profile` file that **you included before**.

# 64 bits user's package installations
export ARCHFLAGS="-arch x86_64"
  • Re-load the bash environment configuration . ~/.bash_profile

Homebrew (AKA Brew)


  • Get XCode from the Apple App Store.

  • Install XCode Command Line Tools. xcode-select --install

  • Download and install brew. ruby -e "$(curl -fsSL"

  • Check that brew has been installed correctly. brew doctor


There are hundreds of packages that will match your needs, but I will include a bunch that fit mines.

  • Python 2.x brew install python --with-brewed-openssl
  • Python 3.x brew install python3 --with-brewed-openssl
  • Git brew install git
  • Wget brew install wget

NOTE: If you want to search for a package, just type brew search PACHAGE_NAME.


Virtual Environments

With Python 2.x pip installer, install virtualenv & virtualenvwrapper

  • Setup Tools pip install --upgrade setuptools
  • PIP pip install --upgrade pip
  • Virtual Environment pip install virtualenv
  • Virtual Environment Wrapper pip install virtualenvwrapper

Restricting pip to virtual environments

  • Create or edit a bashrc file, vim ~/.bashrc and include the following

pip should only run if there is a virtualenv currently activated


cache pip-installed packages to avoid re-downloading

export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache

turning off pip restriction for install or upgrade a global package

e.g.: syspip install --upgrade pip setuptools virtualenv

syspip(){ PIP_REQUIRE_VIRTUALENV="" pip "$@" }

- Re-load the bash environment configuration `. ~/.bash_profile`

#### Virtual Environments Wrappers

In case that is not installed yet,  `pip install virtualenvwrapper`.

- Add to your `bashrc` shell startup file the `WORKON_HOME` directory (`$HOME/.virtualenvs`?), the `PROJECT_HOME` directory (`$HOME/workspace`?) and the command to script file  (`/usr/local/bin/`?)

# Virtual Environment Wrapper
export VIRTUALENVWRAPPER_PYTHON=`which python`
export VIRTUALENVWRAPPER_VIRTUALENV=`which /virtualenv`
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
source /usr/local/bin/
  • Source the bashrc file and create the WORKON_HOME directory. . ~/.bashrc && mkdir -p $WORKON_HOME

Not familiar with virtualenvwrapper?, no worries. virtualenvwrapper command reference

python2.x and python3.x?

Just add an alias to your python3 binary:

alias mkvirtualenv3='mkvirtualenv --python=`echo $(which python3)`'



If you want to get on the terminal prompt the current branch in which you are working, just...

  • Open ~/.bash_profile in your favourite text editor and add the following content to the bottom.

Git branch in prompt

parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/ (\1)/' } export PS1="\u@\h \W[\033[32m]$(parse_git_branch)[\033[00m] $ "

- Re-load the bash environment configuration `. ~/.bash_profile`

## Databases

### PostgreSQL

The easiest way to include a PostgreSQL database system into a OSX is installing [****]( Is is as most of OSX installers, unzip it and move into `Applications` folder.  Include to your `bash_profile` file the following `PATH="/Applications/$PATH"` and source the file `. ~/.bash_profile`

**Note:** The current version of while I am writing this, is 9.3. So the above line may differ depending what version have you installed.

## IDE 

### SublimeText 3

##### Packages

SublimeText has no sense to use it as a IDE if you don't install some packages to make your coding easier and more readable while you code. You can drop a SublimeText package into the right directory (to get the right directory, `Preferences -> Browse Packages`) or you can just take advantage of using **Package Control**.

##### Package Control

###### Installation

If necessary, follow the [official installation guide] (

**Note** Keep in mind that some package installation may require the following steps.

- `⌘ + ⇧ + p`
- Search for `Package Control: Install Package` in the command palette autocomplete dropdown box.
- Press `Enter`

##### Settings

{ "indent_to_bracket": true, "shift_tab_unindent": true, "translate_tabs_to_spaces": true, "trim_trailing_white_space_on_save": true, "ensure_newline_at_eof_on_save": true, "wrap_width": 80, "rulers": [ 79, 99 ], "folder_exclude_patterns": [ ".svn", ".git", ".hg", "CVS", "pycache" ], }

##### Packages

- [Anaconda](
- [Git]( & [GitGutter](
- [SideBarEnhancements](
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment