Use Enthought Canopy’s Python with Oh-My-Zsh

Canopy for Mac and an Oh My Zsh Terminal window

Enthought’s instructions on how to use their Python as the default Python in your terminal are bash specific, so you might be a little confused on how to accomplish the same thing within your Zsh shell. Simply edit your .zshrc (if using vim: {bash inline=”true”}vi ~/.zshrc{/bash}) and find the part that begins with {bash inline=”true”}export PATH=”/usr/bin:/….”{/bash}. This line tells the shell where to look for different packages and in which order to look for them. You need to prepend the PATH so the shell first looks for packages in your Enthought Canopy’s bin folder, like so:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin"
# export MANPATH="/usr/local/man:$MANPATH"
# Use one of the two lines below to use Enthought Canopy's Python in your shell
export PATH=/$HOME/Library/Enthought/Canopy_64bit/User/bin:$PATH
# VIRTUAL_ENV_DISABLE_PROMPT=1 source $HOME/Library/Enthought/Canopy_64bit/User/bin/activate

I believe lines 55 and 56 do the same thing, with line 56 running a script to essentially do what line 55 does. I haven’t found any difference when using one or the other, but personally I use the one on line 55, which just prepends your existing PATH. Just use one line or the other by commenting or uncommenting with the # sign. The last thing to consider is that your path in line 55 might be different than mine, depending on whether or not you have the 64- or 32-bit version. Just change the path accordingly. Once you open a new terminal window, run Python and you should see that you’re now running Canopy’s Python:

Last login: Wed Sep 17 10:48:56 on ttys002
➜  ~  python
Enthought Canopy Python 2.7.6 | 64-bit | (default, Jun  4 2014, 16:42:26)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Your shell will also have access to things like IPython notebook, which is found in Canopy’s library. If you don’t want to use Canopy anymore just comment out line 55 above in your .zshrc file.

Conveniently, Oh My Zsh has a virtualenvwrapper plugin that you can use to automate this process using a virtual machine if, for example, you only want to use Canopy when working in certain folders.

About the author

I like learning, programming, and creating. I'm an incessant problem solver, and have an insatiable desire to absorb information. I'm an information sponge. A critical thinker. My left brain and right brain function as one. Business and technology should be one. I invest based on opportunity or technicals, whichever is right. I never let my schooling interfere with my education. Marketing is not fluff, it is data-driven. I find patterns, and analyze the random. I like to teach and explain.

Leave a Reply