Tag Archives: Python

Scientific Python…the easy way

tl;drUse Anaconda

The scientific programming libraries available for Python are among the best available out there. Libraries such as scipy, scikit-learn and scikit-image the among the easiest to use that I have come across. Of course much of that is due to the fact that Python is an amazing language…but we won’t get into that in this post.

Using the any of these libraries is dead easy once you get the hang of Python. The documentation is also (usually) pretty good. However, installing the libraries and their dependencies can be a pain in the ass. Most of these libraries are updated pretty frequently so you really want to use the latest version at anytime. So while the Debian repository has most of the packages you would need (not sure about other distros), the versions on the repository is usually outdated (with good reason).

One option (for Debian users at least) is neurodebian but I have had some problems with neurodebian in the past. My initial solution was to install as many as of the dependencies as possible from the Debian repositories and using pip for the latest versions of the different libraries. This works fine in most cases. Problem is, when you want to upgrade to newer versions keeping track of how you installed each library, deciding what to upgrade, etc. becomes a pain (which is why we have apt-get…but we’ve already established that we can’t do that).

The next best solution that I have come across is Anaconda from Continuum Analytics. Anaconda installs everything you need for scientific programming in Python (including Python itself) within a directory anywhere on your machine. Works on Mac, Windows and Linux (any distro as far as I know) and is really simple to install. It even comes with Spyder, a MATLAB-like IDE for Scientific Python programming (although I prefer Vim+terminal).

Installing Anaconda

For Mac and Windows, just download the GUI installer and follow the instructions…hard to mess up. For Linux systems, just download the shell script from http://continuum.io/downloads and run it to install anywhere on machine. If you’re installing it within your home directory (or anywhere else you have permissions) you won’t need root access. However, if you are planning on allowing multiple users to have access to Anaconda, I suggest the following approach.

  1. Install Anaconda in /etc/anaconda (you will probably need root access to do this)
    sudo bash installer.sh
    When asked if you want to install Anaconda in /root/anaconda enter /etc/anaconda instead
  2. Create a user group called anaconda
    sudo addgroup anaconda
  3. Next change the ownership of the /etc/anaconda directory
    sudo chown -hR root:anaconda /etc/anaconda
  4. Add the root user to the group anaconda
    sudo adduser root anaconda
  5. Now add any user needs access to Anaconda to the group anaconda. Make sure you use adduser instead of usermod to do this (usermod doesn’t work sometimes)
    sudo adduser username anaconda
  6. (optional) Check that the users were actually added to the group anaconda
    sudo groups username
  7. Finally for each of those users, add the following line to the end of their .bashrc file (usually found in /home/username/.bashrc) using a text editor of your choice
    export PATH="/etc/anaconda/bin:$PATH"
  8. Restart the machine (just in case)

That’s it! Just to see if everything is working fine, run Python. You should see something like the following in the first line.

Python 2.7.5 |Anaconda 1.6.1 (64-bit)| (default, Jun 28 2013, 22:10:09)

The important bit to lookout for is ...|Anaconda.... If you see that everything should be fine.

Notes:

  • I used /etc/anaconda but you can use anything you want really
  • I did this on a Debian 6.0 (squeeze) box. Should be the same for most other systems but just be careful
  • If you ever need to uninstall Anaconda just delete the directory /etc/anacondapiece of pie :-)
  • If you need any help, first place to look is of course the Anaconda documentation. Otherwise, the Anaconda mailing list would be your best bet.
Tagged , ,

How to shoot yourself in the foot.

Gotta love this. Here are some of the better one’s:

C
You shoot yourself in the foot.

C++
You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me over there.”

FORTRAN
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception handling ability.

Cobol
USE HANDGUN.COLT(45), AIM AT LEG.FOOT, THEN WITH ARM.HAND.FINGER ON HANDGUN.COLT(TRIGGER) PERFORM.SQUEEZE RETURN HANDGUN.COLT(45) TO HIP.HOLSTER.

LISP
You shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds…

Basic (interpreted)
You shoot yourself in the foot with a water pistol until your foot is waterlogged and rots off.

Basic (compiled)
You shoot yourself in the foot with a BB using a SCUD missile launcher.

Pascal
The compiler won’t let you shoot yourself in the foot.

Apple
We’ll let you shoot yourself, but it’ll cost you a bundle.

IBM
You insert a clip into the gun, wait half an hour, and it goes off in random directions. If a bullet hits your foot, you’re lucky.

Microsoft
Object “Foot” will be included in the next release. You can upgrade for $500.

Cray
I knew you were going to shoot yourself in the foot.

Hewlett-Packard
You can use this machine-gun to shoot yourself in the foot, but the firing pin is broken.

NeXT
We don’t sell guns anymore, just ammunition.

Sun
Just as soon as Solaris gets here, you can shoot yourself anywhere you want.

Assembler
You try to shoot yourself in the foot, only to discover you must first invent the gun, the bullet, the trigger, and your foot.

csh
After searching the manual until your foot falls asleep, you shoot the computer and switch to C.

HTML
<a target="http://body/lower-half/leg/foot.appendage">Shoot here</a>

Java
The gun fires just fine, but your foot can’t figure out what the bullets are and ignores them.

Perl
You shoot yourself in the foot, but can’t figure out how you did it so you find a dozen new ways to do it.

Python
You shoot yourself in the foot and everything goes so smoothly that you go ahead to to shoot yourself in the other foot then your legs, then your torso and then your head. Problem solved.

Occam
You shoot yourself in both feet at the same time with the same pull of the trigger. You have no idea how it happened, but it did.

ASP (addition by Rodney Benker)
You may load the gun and pull the trigger, but the bullet will only hit your foot if you use Internet Explorer.

How to shoot yourself in the foot (it’s a joke, lighten up!)

Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

pyTwit 0.2.2

pyTwit version 0.2.2 is out now. I don’t have a Windows executable in this one. The biggest change in this version is coloured text. It really makes quite a big difference. A complete list of changes for this release from the previous release is available here or in the ‘CHANGELOG’ file in the archive which you can download here.

Tagged , , ,

Tweets on 2009-03-07

Tagged , , ,

Tweets on 2009-02-08

  • python running haywire on my debian machine #
  • ok fixed python, will work on trac tomorrow…nite all #
Tagged , ,

pyTwit 0.2.1

I just uploaded a new version of pyTwit. It fixes a bug in the previous version. The ‘timeline’ command was throwing up an index error so this fixes it. Many thanks to Jeff Dimond for reporting it in the first place.

Tagged , , , , ,

pyTwit

I’ve decided to call my Twitter app pyTwit. I’ve searched the Twitter Fan Wiki list of apps and there doesn’t seem to be a pyTwit yet so I’ve decided to claim the name (hey it rhymes!)

Anyways, I did a version 0.1.1 which was basically adding the functionality for posting tweets but I’ve also added many more features (like displaying multiple timelines and a command system for using the different features) and redesigned the code structure so I’ve decided to call this one version 0.2

You can check it out here. I’ve also included a compiled Windows executable in the archive for those who are unfortunate enough to be running using Microsuck Windows…me included :(

Tagged , , ,

My own Twitter app

OK I know we really don’t need yet another Twitter app but I’m doing this to practice programming in python. This is version 0.1 so I’ll definately add more stuff as I go along.

I’m using the XML feed from the Twitter REST API. I know there are modules to process the XML feed (like minidom and sax) but I decided to write my own method for processing the feed for educational purposes. My method won’t work with any feed (yet) but it’ll work fine for the Twitter feed.

At the moment, the app will only get your friends timeline and display it for you. I’ll add more functionality later this week if I have the time. In the mean time please try it out. All comments/criticism/suggestions/feedback are welcomed.

twitter.py

Tagged , , ,