Skip navigation

Monthly Archives: April 2016

I have been meaning to post about this topic for awhile, but due to work and life I haven’t had the time or energy to write posts for this blog.  Anyways, let’s get to it.

About two or three years ago I was just getting started with python.  I had a few little python projects I was working on and was starting to explore the data analysis tools in the python ecosystem.  I stumbled across the Anaconda python distribution which offers a python distribution and packaging system that comes with all of the non-python dependencies required by many of the data analysis focused packages (matplotlib, numpy, etc…).  Having recently experienced some of the struggles of getting up and running with these packages, I decided to give Anaconda a try.  After all, what is the worst that can happen….

The installation was fairly painless, just download the installer, run the bash script and respond to the questions when prompted. Accepting the ‘Terms and Conditions’ was a little annoying[1], but overall it was a pretty painless install and before I knew it I was up and running with ipyhton notebook, matplotlib, and pandas.  It was nice that everything just worked out of the box, and the environment and package management systems seemed to be pretty cool.  After playing around with Anaconda for a bit, I decided to switch back to working on one of my python projects and to my dismay, nothing was working!

After a very long and frustrating afternoon, I eventually figured out that I had accidentally allowed the Anaconda installer to prepend the path of the anaconda distribution into my .bashrc file.  So when I tried to run my python existing python projects (all of which were in virtualenvs)  I got errors related to the python version that was being used (can’t re-call the exact errors, it’s been awhile).  After some more time of trying to figure out a way to get virtualenvs to work within conda (Anaconda’s environment isolation tool), I decided to just uninstall Anaconda and restore my original .bashrc.

It’s worth mentioning that not only was a fairly new to python, but I was also fairly new to Linux at the time as well.  Had I been a little more experienced, I would have known that I could just restore the original .bashrc file without uninstalling Anaconda, and things would have returned to normal for my existing python projects.  I eventually settled on a sub-optimal solution where i installed Anaconda into a separate chroot (essentially a sandboxed OS).  As such, I never really used it that much due to the difficulty switching between the two environments.

A year or two later, I got a job as a data engineer with a solar analytics company.  While most of my work involves building out a data warehouse, occasionally I do some analytical work where Anaconda would be very useful.  So after some digging on the interwebs, I stumbled across a few blog posts that provided what seemed like a good solution.  In hindsight, this should have been obvious, but essentially the solution is to tell Anaconda ‘No’ when it asks to prepend the path to .bashrc, and after the isntallation is complete, add a few lines to your .bash_profile (on Mac) that allows you to jump into Anaconda.  The line I use is:

alias enterconda='export PATH="/Users/pyoung/anaconda/bin:$PATH" && PS1="\u@anaconda:\w\$"'

So now when I want to use Anaconda, I just type <code>enterconda</code> in a terminal, and from there I can launch an ipython notebook sessions or drop into a python shell and have access to all of the popular python data tools.

[1] You had to scroll through the entire text of the Terms document (either using the enter key or the down key, can’t remember which), and when you got to the bottom if you didn’t release the key at the ‘Do you accept’ prompt, it would abort the installation with a message like ‘You must accept the terms and conditions in order to use Anaconda.’  Essentially it was accepting the scroll key as a valid negative input to their ‘Terms and Conditions’ prompt.  It took a few attempts to get past this (the T&C was real long, and who reads those things anyway!).