(c) 2016 Justin Bois. This work is licensed under a Creative Commons Attribution License CC-BY 4.0. All code contained herein is licensed under an MIT license.
This tutorial was generated from a Jupyter notebook. You can download the notebook here.
In this lesson, you will set up a Python computing environment for scientific computing. In addition, you will set up a GitHub account, which you will use to collaborate on and submit all exercises of the course.
There are two main ways people set up Python for scientific computing.
In this class, we will use Anaconda, with its associated package manager, conda
. It has recently become the de facto package manager/distribution for scientific use.
We are at an interesting point in Python's history. Python is currently in version 3.5 (as of September 20, 2016). The problem is that Python 3.x is not backwards compatible with Python 2.x. Many scientific packages were written in Python 2.x and have been very slow to update to Python 3. However, Python 3 is Python's present and future, so all packages eventually need to work in Python 3. Today, most important scientific packages work in Python 3. All of the packages we will use do, so we will use Python 3 in this course.
For those of you who are already using Anaconda with Python 2, you can create a Python 3 environment.
Mac users: Before installing Anaconda, be sure you have XCode installed.
Downloading and installing Anaconda is simple.
That's it! After you do that, you will have a functioning Python distribution.
Note: Do the steps below only after you have finished the installation of Anaconda.
During the bootcamp, you will need to access the command line. Doing this on a Mac or Linux is simple. If you are using Linux, it's a good bet you already know how to navigate a terminal, so we will not give specific instructions for Linux. For a Mac, you can fire up the Terminal application. It is typically in the /Applications/Utilities
folder. Otherwise, hold down Command ⌘
-space bar and type "terminal" in the search box, and select the Terminal Application.
For Windows, download and install Git Bash. After you have installed it, simply right click anywhere on your Desktop, and you should have an option to run Git Bash (at least that's what happens on Windows 7). You will then have a prompt that looks very much like Mac and Linux users will have.
conda
package manager¶conda
is a package manager for keeping all of your packages up-to-date. It has plenty of functionality beyond our basic usage in class, which you can learn more about by reading the docs. We will primarily be using conda
to install and update packages.
conda
works from the command line. Now that you know how to get a command line prompt, you can start using conda
. The first thing we'll do is update conda
itself. To do this, enter the following on the command line:
conda update conda
If conda
is out of date and needs to be updated, you will be prompted to perform the update. Just type y
, and the update will proceeed.
Now that conda
is updated, we'll use it to see what packages are installed. Type the following on the command line:
conda list
This gives a list of all packages and their versions that are installed. Now, we'll update all packages, so type the following on the command line:
conda update --all
You will be prompted to perform all of the updates. They may even be some downgrades. This happens when there are package conflicts where one package requires an earlier version of another. conda
is very smart and figures all of this out for you, so you can almost always say "yes" (or "y
") to conda
when it prompts you.
For almost the entirely of the course, we will do all work in Jupyter notebooks. This is not the best workflow for larger projects. It is better to have separate Python scripts. Furthermore, you might want to be building your own module of useful utilities for the course, which will be written using text files.
There are countless options for text editors. For example, Anaconda comes with an interactive developer environment (IDE) called Spyder, which is built for scientific computing. Sublime Text is a widely used text editor. I have happily used Light Table in the past. At the moment, I recommend using Atom, which is currently my own text editor of choice.
To download and install Atom, go to its website and follow the instructions. Once it's installed, you have a good text editor to use in the bootcamp and beyond.
The default configuration of Atom will work well for you, but you have to be careful with how tabs are defined. In the Atom menu, go to
Packages -> Settings View -> Open
This will open the Settings page for Atom. Scroll toward the bottom of that page, and make sure Tab Length
is set to 4. Underneath that, make sure Tab Type
is set to soft
. As you will soon learn, this is important in Python because indentation matters.
We will make extensive use of Git during the course. We will use GitHub to host the repositories. You need to set up a GitHub account and get yourself acquainted with the basics of Git. To do this, see this tutorial from my Intro to Programming Bootcamp.
After setting up Git on your machine, you can clone a repository of utilities the course staff has provided (and will be updating throughout the course). You can clone this repository as follows.
git clone https://github.com/justinbois/bebi103_utils.git
Once you have a GitHub account, send an email to bois at caltech dot edu
with your account ID to get access to the BE/Bi 103 Group on GitHub. Within this group, you will form a team. Your team consists of your partners for homework submission.