Archive for the ‘python’ Category

Editing .bash_profile

I came across a very useful blog post here about customising the bash shell by editing .bash_profile in nano, a terminal editor for Unix systems that comes with OSX.

In my previous post I talked about using a second Python install on my Macbook and being able to start it in interactive mode on the terminal by modifying the PATH variable.  Without doing this, the original Python install would be the one being targeted.  Well, instead of having to type this line every time I open the Terminal window, I just had to add it to .bash_profile and now every terminal session receives this setting.

editing .bash_profile with nano

Posted by admin on November 1st, 2009 No Comments

Setting up Python on my Macbook Pro

I bought a MacBook Pro a couple of months ago (having always worked on Windows) and have started to learn Python.  The first step was to install Python but OSX 10.5.7 actually comes with Python 2.5 pre-installed.  This was handy to get up and running, allowing me to type Python code in the terminal straight away and helping me check that I installed Pydev correctly but I decided to take this advice and upgrade to a newer version.

I opted for ActiveState's Python distribution 2.6.2.2.  I'm really liking the modular nature of Python and using easy_install and pip.  A problem arose, however, when it came to targeting my second Python installation.  The easy_install exe program will target the default installation since it is defined on the System PATH variable.  ActiveState sets up a symbolic link for Python in /usr/local/bin and you can make ActivePython first on your PATH in the terminal window by entering the following:

PATH=/usr/local/bin:$PATH; export PATH

Now when I start Python in the terminal it will be version 2.6.2.2 (i.e., my second installation).  By exiting Python (ctrl+d), I can then add packages (such as numpy) that target this version using either easy_install or pip commands:

easy_install numpy

If I wanted to install a package that I downloaded that has a '.pkg' file extension I found that it also targeted the default Python install for the same reason.  My solution was to also install the package from the terminal by doing the following:

PATH=/usr/local/bin:$PATH; export PATH
cd /Volumes/wxPython2.8-osx-unicode-2.8.10.1-universal-py2.6/
sudo installer -pkg wxPython2.8-osx-unicode-2.8.10.1-universal-py2.6.pkg -target "/"

This is pretty standard stuff but I thought I'd share since it took me a little while to figure out :)

Posted by admin on September 20th, 2009 3 Comments