The material in this document is taken from Appendix H.1 in the book A Primer on Scientific Programming with Python, 4th edition, by the same author, published by Springer, 2014.
You can avoid installing Python on your machine completely by using a web service that allows you to write and run Python programs. Computational science projects will normally require some kind of visualization and associated graphics packages, which is not possible unless the service offers IPython notebooks. There are two excellent web services with notebooks: SageMathCloud at https://cloud.sagemath.com/ and Wakari at https://www.wakari.io/wakari. At both sites you must create an account before you can write notebooks in the web browser and download them to your own computer.
Sign in, click on New Project, give a title to your project and
decide whether it should be private or public, click on the project
when it appears in the browser, and click on Create or Import a File,
Worksheet, Terminal or Directory.... If your Python program needs
graphics, you need to choose IPython Notebook, otherwise you can
choose File. Write the name of the file above the row of
buttons. Assuming we do not need any graphics, we create a plain Python
file, say with name
py1.py
. By clicking File you are brought to a browser window with
a text editor where you can write Python code. Write some code and
click Save. To run the program, click on the plus icon (New),
choose Terminal, and you have a plain Unix terminal window where you
can write python py1.py
to run the program. Tabs over the terminal
(or editor) window make it easy to jump between the editor and the
terminal. To download the file, click on Files, point on the
relevant line with the file, and a download icon appears to the very
right. The IPython notebook option works much in the same way, see
the section Writing IPython notebooks.
After having logged in at the wakari.io
site, you automatically
enter an IPython notebook with a short introduction to how the
notebook can be used. Click on the New Notebook button to start a
new notebook. Wakari enables creating and editing plain Python files too:
click on the Add file icon in pane to the left, fill in the program
name, and you enter an editor where you can write a program. Pressing
Execute launches an IPython session in a terminal window, where you
can run the program by run prog.py
if prog.py
is the name of the
program. To download the file, select test2.py
in the left pane and
click on the Download file icon.
There is a pull-down menu where you can choose what type of terminal window you want: a plain Unix shell, an IPython shell, or an IPython shell with Matplotlib for plotting. Using the latter, you can run plain Python programs or commands with graphics. Just choose the type of terminal and click on +Tab to make a new terminal window of the chosen type.
Both SageMathCloud and Wakari let you install your own Python
packages.
To install any package packagename
available at PyPi, run
pip install --user packagename
To install the SciTools package, which is useful when working with this document, create a Terminal (with a Unix shell) and run the command
pip install --user -e \
git+https://github.com/hplgit/scitools.git#egg=scitools