Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Python 2.7 (homebrew + pip + virtualenv) on Mac OS X Lion

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

$ mkdir ~/Frameworks
$ ln -s "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework" ~/Frameworks
$ /usr/local/share/python/easy_install pip
$ /usr/local/share/python/pip install --upgrade distribute

Add to .bashrc:

# Before other PATHs...
PATH=${PATH}:/usr/local/share/python

# Python
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
if [[ -r /usr/local/share/python/virtualenvwrapper.sh ]]; then
    source /usr/local/share/python/virtualenvwrapper.sh
else
    echo "WARNING: Can't find virtualenvwrapper.sh"
fi

Install virtualenv

$ pip install virtualenv 
$ pip install virtualenvwrapper

Test setup

$ mkvirtualenv test 
$ rmvirtualenv test
@erasmospunk

This comment has been minimized.

Show comment
Hide comment
@erasmospunk

erasmospunk Jun 13, 2012

Hi,

Is there a reason you put PATH=${PATH}:/usr/local/share/python instead of PATH=/usr/local/share/python:${PATH} ?

Thanks!

erasmospunk commented Jun 13, 2012

Hi,

Is there a reason you put PATH=${PATH}:/usr/local/share/python instead of PATH=/usr/local/share/python:${PATH} ?

Thanks!

@pithyless

This comment has been minimized.

Show comment
Hide comment
@pithyless

pithyless Jun 13, 2012

Hmmmm... I can't recall any reason this would be. It looks like a typo. (I don't have my MacBook around to verify)

Owner

pithyless commented Jun 13, 2012

Hmmmm... I can't recall any reason this would be. It looks like a typo. (I don't have my MacBook around to verify)

@erasmospunk

This comment has been minimized.

Show comment
Hide comment
@erasmospunk

erasmospunk Jun 14, 2012

So with these steps I get the virtualenv running with py2.7.3 but in the normal command line I get the system's py2.7.1...

To have the latest python in normal enviroment I have this in .bashrc (that is loaded from .bash_profile):
PATH=/usr/local/share/python:/usr/local/bin/:${PATH}

erasmospunk commented Jun 14, 2012

So with these steps I get the virtualenv running with py2.7.3 but in the normal command line I get the system's py2.7.1...

To have the latest python in normal enviroment I have this in .bashrc (that is loaded from .bash_profile):
PATH=/usr/local/share/python:/usr/local/bin/:${PATH}

@joe--

This comment has been minimized.

Show comment
Hide comment
@joe--

joe-- Nov 14, 2012

This was super helpful :)

joe-- commented Nov 14, 2012

This was super helpful :)

@johnhaitas

This comment has been minimized.

Show comment
Hide comment
@johnhaitas

johnhaitas Feb 2, 2013

changing
brew install readline sqlite gdbm
to
brew install readline sqlite gdbm --universal
helped me

johnhaitas commented Feb 2, 2013

changing
brew install readline sqlite gdbm
to
brew install readline sqlite gdbm --universal
helped me

@benguillet

This comment has been minimized.

Show comment
Hide comment
@benguillet

benguillet Feb 20, 2013

Same than @johnhaitas, add to add the --universal for the install of readline sqlite and gdbm

benguillet commented Feb 20, 2013

Same than @johnhaitas, add to add the --universal for the install of readline sqlite and gdbm

@steakknife

This comment has been minimized.

Show comment
Hide comment
@steakknife

steakknife Mar 10, 2013

Helpful 👍

steakknife commented Mar 10, 2013

Helpful 👍

@newtoncalegari

This comment has been minimized.

Show comment
Hide comment
@newtoncalegari

newtoncalegari Apr 11, 2013

I had to add the --universal for the install the sqlite and gdbm because when I tried to install python it showed this error:

Error: python dependency sqlite not installed with:
    --universal

newtoncalegari commented Apr 11, 2013

I had to add the --universal for the install the sqlite and gdbm because when I tried to install python it showed this error:

Error: python dependency sqlite not installed with:
    --universal
@bigfolio

This comment has been minimized.

Show comment
Hide comment
@bigfolio

bigfolio Jul 2, 2013

I get a:

WARNING: Can't find virtualenvwrapper.sh

From the .bashrc

bigfolio commented Jul 2, 2013

I get a:

WARNING: Can't find virtualenvwrapper.sh

From the .bashrc

@sbrieuc

This comment has been minimized.

Show comment
Hide comment
@sbrieuc

sbrieuc Aug 6, 2013

I had to change from:

    if [[ -r /usr/local/share/python/virtualenvwrapper.sh ]]; then
        source /usr/local/share/python/virtualenvwrapper.sh

to

    if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
        source /usr/local/bin/virtualenvwrapper.sh

to make it work, because virtualenvwrapper.sh got installed there.

sbrieuc commented Aug 6, 2013

I had to change from:

    if [[ -r /usr/local/share/python/virtualenvwrapper.sh ]]; then
        source /usr/local/share/python/virtualenvwrapper.sh

to

    if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
        source /usr/local/bin/virtualenvwrapper.sh

to make it work, because virtualenvwrapper.sh got installed there.

@the-shank

This comment has been minimized.

Show comment
Hide comment
@the-shank

the-shank Feb 2, 2014

Thanks for this.

Just wanted to point out that I had to do this

brew install readline sqlite gdbm --universal

to get it to work

the-shank commented Feb 2, 2014

Thanks for this.

Just wanted to point out that I had to do this

brew install readline sqlite gdbm --universal

to get it to work

@mistydemeo

This comment has been minimized.

Show comment
Hide comment
@mistydemeo

mistydemeo Feb 13, 2014

$ brew install python --universal --framework

Homebrew already does dependency resolution - no need for this line!

mistydemeo commented Feb 13, 2014

$ brew install python --universal --framework

Homebrew already does dependency resolution - no need for this line!

@shurane

This comment has been minimized.

Show comment
Hide comment
@shurane

shurane Feb 13, 2014

A lot has changed in homebrew and these instructions are out of date. brew install --universal should take care of most of your problems. Also take a look at brew info python for installation instructions.

shurane commented Feb 13, 2014

A lot has changed in homebrew and these instructions are out of date. brew install --universal should take care of most of your problems. Also take a look at brew info python for installation instructions.

@bdejong

This comment has been minimized.

Show comment
Hide comment
@bdejong

bdejong Sep 3, 2014

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
    source /usr/local/bin/virtualenvwrapper.sh
else
    echo "WARNING: Can't find virtualenvwrapper.sh"
fi

Also seems to be more recent...

bdejong commented Sep 3, 2014

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
    source /usr/local/bin/virtualenvwrapper.sh
else
    echo "WARNING: Can't find virtualenvwrapper.sh"
fi

Also seems to be more recent...

@huanghaihui

This comment has been minimized.

Show comment
Hide comment
@huanghaihui

huanghaihui Dec 18, 2014

After install python, I find easy_install, virtualenvwrapper.sh and so on in /usr/local/bin not in /usr/local/share/python. just like bdejong shows above.

huanghaihui commented Dec 18, 2014

After install python, I find easy_install, virtualenvwrapper.sh and so on in /usr/local/bin not in /usr/local/share/python. just like bdejong shows above.

@yodaqua

This comment has been minimized.

Show comment
Hide comment
@yodaqua

yodaqua Apr 15, 2017

still useful, thanks

yodaqua commented Apr 15, 2017

still useful, thanks

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