{"id":442,"date":"2011-06-01T22:01:12","date_gmt":"2011-06-02T03:01:12","guid":{"rendered":"http:\/\/www.insomnihack.com\/?p=442"},"modified":"2011-06-01T22:01:12","modified_gmt":"2011-06-02T03:01:12","slug":"multiple-python-versions-on-osx-with-virtualenv-and-homebrew","status":"publish","type":"post","link":"http:\/\/www.insomnihack.com\/?p=442","title":{"rendered":"Multiple Python Versions on OSX with Virtualenv and Homebrew"},"content":{"rendered":"<p>Since writing my post on configuring <a title=\"Multiple Python Versions on OSX with Virtualenv and Macports\" href=\"http:\/\/www.insomnihack.com\/?p=421\">multiple versions of Python on OSX with Virtualenv and Macports<\/a>, I&#8217;ve switched from Macports to <a title=\"Homebrew\" href=\"http:\/\/mxcl.github.com\/homebrew\/\">Homebrew<\/a> as my package manager for Unix utilities on OSX. I did this for a couple of reasons. Homebrew seems to install less dependencies than Macports or Fink. Also, most of my Python development has settled on Python 2.7 and occasionally Python 3 for tasks that don&#8217;t require external libraries that only run on Python 2.x. So for me, an easier install with less gunk on my hard drive is a fair trade for losing the latest updates to Python 2.4, 2.5, and 2.6.\u00a0In this post, I&#8217;ll describe my setup.<\/p>\n<p>The first thing I did was <a title=\"Uninstalling Macports\" href=\"http:\/\/guide.macports.org\/#installing.macports.uninstalling\">uninstall Macports<\/a>. Homebrew has fairly up-to-date versions all of the Unix packages I use on a daily basis, including git, subversion, bash_completion, Python, Qt, PyQt, and their supporting libraries. As such, I don&#8217;t need Macports taking up additional hard drive space and potentially causing conflicts with Homebrew&#8217;s packages.<\/p>\n<p>Next, I installed (or update) <a title=\"pip documentation\" href=\"http:\/\/www.pip-installer.org\/en\/latest\/\">pip<\/a>, <a title=\"virtualenv documentation\" href=\"http:\/\/www.virtualenv.org\/en\/latest\/\">virtualenv<\/a>, and <a title=\"virtualenvwrapper home\" href=\"http:\/\/www.doughellmann.com\/projects\/virtualenvwrapper\/\">virtualenvwrapper<\/a> in my Mac&#8217;s default Python (2.6.1 on Snow Leopard) via easy_install (or pip itself). These are usually the only 3rd-party Python packages I install in the system Python&#8217;s site-packages folder.<\/p>\n<p>The next step is to <code>brew install<\/code> the packages I mentioned above. If you&#8217;re looking for a Unix port other than those I use, check out the <a title=\"Homebrew formula folder on Github\" href=\"https:\/\/github.com\/mxcl\/homebrew\/tree\/master\/Library\/Formula\/\">formula folder on Github<\/a> for the current list of packages supported by Homebrew. You can also use <code>brew search<\/code> to get a list at the Terminal (fwiw, I use <a title=\"iTerm\" href=\"http:\/\/iterm.sourceforge.net\/\">iTerm<\/a>).<\/p>\n<p>Next, I remove the Macports configuration from my bash ~\/.profile and replace it with the following:<\/p>\n<p>[text]<br \/>\n# virtualenvwrapper<br \/>\nexport WORKON_HOME=$HOME\/VirtualEnvs<br \/>\nif [ -f \/usr\/local\/bin\/virtualenvwrapper.sh ]; then<br \/>\n    source \/usr\/local\/bin\/virtualenvwrapper.sh<br \/>\nfi<\/p>\n<p># bash completion<br \/>\nif [ -f `brew &#8211;prefix`\/etc\/bash_completion ]; then<br \/>\n     . `brew &#8211;prefix`\/etc\/bash_completion<br \/>\nfi<\/p>\n<p># Python 2.6.1<br \/>\nalias mkve26=&#8217;mkvirtualenv &#8211;no-site-packages&#8217;<br \/>\n# Python 2.7.1<br \/>\nalias mkve=&#8217;mkvirtualenv &#8211;no-site-packages &#8211;python=\/usr\/local\/Cellar\/python\/2.7.1\/bin\/python&#8217;<br \/>\nalias mkveqt=&#8217;mkvirtualenv &#8211;python=\/usr\/local\/Cellar\/python\/2.7.1\/bin\/python&#8217;<br \/>\nalias designer=&#8217;open \/usr\/local\/Cellar\/qt\/4.7.2\/bin\/Designer.app&#8217;<br \/>\n# Python 3.2<br \/>\nalias mkve3=&#8217;mkvirtualenv &#8211;no-site-packages &#8211;python=\/usr\/local\/Cellar\/python3\/3.2\/bin\/python3&#8242;<\/p>\n<p># Ammend python path for Homebrew PyQt<br \/>\nexport PYTHONPATH=\/usr\/local\/lib\/python:$PYTHONPATH<br \/>\n[\/text]<\/p>\n<p>The first couple of sections set up the Terminal for bash completion and virtualenvwrapper commands. The third section sets up my virtualenv aliases: one for the default system python, one for Python 2.7, one for Python 2.7 and PyQt, and another for Python 3.2. Python 3 support was added to virtualenv in version 1.6, so you no longer need to <a title=\"Python 3 with Virtualenv and Macports\" href=\"http:\/\/www.insomnihack.com\/?p=435\">jump through hoops<\/a> to get it working with Pythyon 2.x.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since writing my post on configuring multiple versions of Python on OSX with Virtualenv and Macports, I&#8217;ve switched from Macports to Homebrew as my package manager for Unix utilities on OSX. I did this for a couple of reasons. Homebrew seems to install less dependencies than Macports or Fink. Also, most of my Python development [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[9,6,8],"_links":{"self":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/442"}],"collection":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=442"}],"version-history":[{"count":0,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/442\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}