Skip to content

Instantly share code, notes, and snippets.

@munhitsu
Last active November 29, 2020 09:10
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save munhitsu/1034876 to your computer and use it in GitHub Desktop.
Save munhitsu/1034876 to your computer and use it in GitHub Desktop.
python 2.7.5 install on OSX (10.8+) using brew (pip, easy_install, virtualenv, virtualenvwrapper)
# In case you had some strange python installation
# NOTE: .pydistutils.cfg seems to be not compatible with brew install python
# areas I needed to clean before installation
# clean up ~/Library/Python
# clean up .local
# preconditions:
# xcode with command line tools installed
xcode-select --install
# homebrew: https://github.com/mxcl/homebrew/wiki/Installation
brew install python --framework
#### update/create your .bash_profile
#homebrew
export PATH=/usr/local/bin:/usr/local/sbin:${PATH}
#virtualenv wrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
#### end of .bash_login
# start new shell and make sure you are using /usr/local/bin/python
# note that it will complain that /usr/local/bin/virtualenvwrapper.sh does not exist
# as we havent installed virtualenvwrapper yet
which python
python --version
# make sure its python >=2.7.5
# time to install virtualenvironment
pip install virtualenvwrapper
mkdir $HOME/.virtualenvs
# start new shell and from now on you will have access to mkvirtualenv
# NOTE: that the only time you should be asked for yout password is during homebrew installation
# if all goes correctly than none of above commands would ask you for your passoword / would want you to use sudo
@fffabs
Copy link

fffabs commented Jul 19, 2011

As recommended here http://docs.python-guide.org/en/latest/starting/installation/ it's probably best to use
brew install python --framework
to compile a Framework-style Python build, rather than a UNIX-style build.

@munhitsu
Copy link
Author

Nice finding, just updating - thanks!

PS: I'll need to check their recommendation to install pip through brew
brew install pip

@fffabs
Copy link

fffabs commented Jul 19, 2011

Good idea! I just checked it, brew doesn't have that formula anymore, so I did it via Distribute:

$ curl -O http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
$ easy_install pip

@fitzgeraldsteele
Copy link

This was helpful for me today...thanks!

@munhitsu
Copy link
Author

I'm glad to hear it!

@tpisto
Copy link

tpisto commented Sep 3, 2012

Saved much time today! Thanks!

@munhitsu
Copy link
Author

updated to capture 10.8 and homebrew changes

@munhitsu
Copy link
Author

Updated from .bash_login to .bash_profile to avoid common issues

A quote from man bash:
"When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable."

@munhitsu
Copy link
Author

munhitsu commented Jan 4, 2016

On OSX 10.11 I prefer to keep brew outside of /usr/local as it interferes with newly introduced OSX filesystem protection.
I typically just clone homebrew to /brew

@flavio-fernandes
Copy link

thanks for this!

nitpick: in the note: "Updated from .bash_login to .bash_profile to avoid common issues"
it seems that you may have forgotten to update line 23, so the start and end markers are consistent.

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