Scientific Python Installation

Introduction

As engineers, we need to install not only Python, but the necessary modules and tools for doing scientific stuff, matrices, arrays, plotting, and so on. This is sometimes call the scipy stack among scientific python people. Instructions for different operating systems are below:

Windows

The easiest way to get everything you need for scientific python on windows is to install Anaconda. Note that once you install Anaconda, you do not need to install anything else. Go to https://store.continuum.io/cshop/anaconda/ and choose “Download Anaconda”. You almost certainly want the 64-bit version for Python 3.5.

Key Points

  • we need more than just Python, so installing Anaconda is easiest
  • accept all the defaults
  • let Anaconda install into C:\Anaconda
    • do not install into a path that contains spaces in any folder names
  • configure Spyder to load numpy and pylab on launch and not to use inline

Windows Install Videos

I made several install videos for downloading, installing, and configuring anaconda and spyder in windows:

Windows Verification

  • In Windows, you basically need to install Anaconda and configure Spyder and you should be good to go
  • You have a working scientific Python installation when you can plot a sine wave
  • Launch Spyder from the windows start button search and type this code into the IPython console in the bottom right this code:
t = arange(0,1,0.01)
y = sin(2*pi*t)
figure(1)
clf()
plot(t,y)
show()

If that code executes without an error and you see a sine wave in a plot window, you are good to go.

Mac OSX

Mac users have two options. The first is to install Anaconda. Anaconda is easy, but it also takes up a lot of hard drive space. If you have any interest in learning to use the terminal and unleashing its power, I strongly encourage you to use homebrew and pip.

Anaconda

If you choose to go the Anaconda route, go to https://store.continuum.io/cshop/anaconda/ and choose “Download Anaconda”.

Homebrew and PIP

For Mac users, I strongly recommend using homebrew and pip to install the things we need. This blog is a pretty good explanation, but note that his ruby command for installing homebrew itself is outdated:

http://penandpants.com/2012/02/24/install-python/

Basically, you need to first install Xcode. You used to have to register as a developer with Apple to do this. It was free, but you had to register. You might now be able to install it directly from the app store.

Once you have Xcode installed, install homebrew. Homebrew is a tool for installing Unix and Linux open-source software from the command line. You install homebrew with this command from the terminal:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You then have to add this line to your ~/.profile file (~ means your home directory):

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

Use homebrew to install python by typing this at the terminal:

brew install python

Important Check

If you homebrew installed correctly and homebrew installed its own python, you should be able to type which python at the terminal and the response must be:

/usr/local/bin/python

PIP

Pip is a python installation tool. To get it type

easy_install pip

Note: installing gcc and scipy can take up to an hour depending on your internet connection and processor speed. Don’t start these processes if you can’t let your computer run for a bit. You should be able to do other things while it is working in the background, but don’t stop these processes or shutdown your computer until they finish.

You will also need a fortran compiler to install scipy. It is in the gcc package. Type:

brew install gcc

Once you have pip and gcc, you can install the following:

pip install numpy

pip install scipy

We need one last random thing from homebrew:

brew install pkg-config

and then we can wrap up with

pip install matplotlib

pip install ipython

pip install pyserial

Mac OSX Spyder Installation

Once you have python and the scientific packages installed, I recommend installing the Spyder IDE if you prefer an integrated development environment:

Mac OSX Verification

You have correctly installed scipy and friends in OSX when you can generate a sine wave as described above in the code block ipythoncode under Windows Verifciation. You can do this either in Spyder or using IPython from the terminal.

See the links above for SpyderVideos on verificaiton and tips.

To launch IPython from the terminal, open a terminal and type

ipython --pylab --profile=scipy

this can be saved as an alias in a file called .profile in your home directory:

alias scipy='ipython --pylab --profile=scipy'

Ubuntu

Ubuntu users should be able to do something like

sudo apt-get install python-numpy python-scipy python-matplotlib ipython

and then launch IPython as described for OSX. The alias would need to go in a file called .bash_profile. Plotting a sine wave would prove basic functionality as described above in ipythoncode.