Most of the development/experimentation I was doing with scikit-learn’s machine learning algorithms was on my local development machine. But eventually I needed to do some heavy duty model training / cross validation, which would take weeks on my local machine. So I decided to make use of one of the cheaper compute optimized EC2 instances that AWS offers.
Unfortunately I had some trouble getting scikit-learn to install on a stock Amazon’s EC2 Linux, but I figured it out eventually. I’m sure others will run into this, so I thought I’d write about it.
Note: you can of course get an EC2 community image or an image from the EC2 marketplace that already has Anaconda or scikit-learn and tools installed. This guide is for installing it on a stock Amazon EC2 Linux instance, in case you already have an instance setup you want to use.
In order to get scikit-learn to work, you’ll need to have pandas, scipy and numpy installed too. Fortunately Amazon EC2 Linux comes with python 2.7 already installed, so you don’t need to worry about that.
Start by ssh’ing into your box. Drop into rootshell with the following command (if you’re going to be typing “sudo” before every single command, might as well be root by default anyway, right?)
First you need to install some development tools, since you will literally be compiling some libraries in a bit. Run the following commands:
yum groupinstall ‘Development Tools’
yum install python-devel
Next you’ll install the ATLAS and LAPACK libraries, which are needed by numpy and scipy:
yum install atlas-sse3-devel lapack-devel
Now you’re ready to install first all the necessary python libraries and finally scikit-learn:
pip install numpy
pip install scipy
pip install pandas
pip install scikit-learn
Congratulations. You now have scikit-learn installed on the EC2 Linux box!
4 thoughts on “Installing pandas, scipy, numpy, and scikit-learn on AWS EC2”
I’m getting an error message when i get to the pandas install saying:
Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-j_5oh5lg/pandas
Any ideas what i can do to workaround?
Hello Dominic. Unfortunately I haven’t messed around with it in a while, so I’m not sure.
modify one command…
yum install atlas-sse3-devel lapack-devel freetype-devel
Doesn’t work for me :/
Command “/usr/bin/python2.7 -c “import setuptools, tokenize;__file__=’/tmp/pip-build-pHwlQU/scikit-learn/setup.py’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –record /tmp/pip-63vuBq-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-pHwlQU/scikit-learn