Skip to content

Getting Started

Parag Rastogi edited this page Nov 17, 2017 · 16 revisions

I will assume you have a Windows computer and an internet connection. You can use most of these commands in a Linux command line as well - just make sure you get Linux distros from the web instead of Windows ones! I have developed these scripts using Python 3.6.3 and Jupyter 4.3.0.

1. Installing Python

Do you already have Python 3 (any version, but preferably 3.6) installed? Great, you're winning already. Skip ahead to the next section.

If not, go to the conda website and install the 64-bit version for Python 3.6. Anaconda is just one distribution of Python (and R) - feel free to install the latest basic python from the project's own website.

NB: I will use the command conda install to install packages below. If you would like to use the basic python distro, then you must use pip install.

Open the command prompt by pressing Windows+R and typing cmd in the little window that appears. The command prompt is that dank black screen with a blinking cursor that all the strange computer people seem to have on their screens, shown here in all its glory. Your parents or professors might call it the "MS-DOS prompt". Ignore them, they are wrong.

In the command prompt, type:

python --version

You should see something like this:

Python 3.6.3 :: Anaconda, Inc.

If you don't see this or you see an error, it could mean one of two things: you haven't installed Python or the command python is not in your PATH variable. See this helpful link to resolve the latter issue.

Set up with Python? Good! Proceed to step 2.

2. Downloading this repository

In your browser, go to the github repo. On that page, you should see a green button labelled Clone or download. Click on that to see options. The easiest is to download the repository as a ZIP file. You can also copy the git link (same as the web address but ending in .git) and use git on your computer to clone or fork the repo. See this webpage for instructions on how to download and use git. Don't be afraid to use the command line interface for big girls/boys.

3. Installing Python modules

Basic Python is pretty nifty, but a lot of the magical maths we will use needs special libraries. You can install the modules/packages/libraries needed for this tutorial in two ways: with a batch file or with individual command prompt commands.

Batch File

Double-click on the file in the installers directory called RunThis_Windows.bat and watch the packages install themselves in the command window that will pop up. The script will ask you to enter the name of the package manager you would like to use (pip or conda):

Enter the name of your preferred package manager (in lower case):

Make sure you enter the name conda in lower case, otherwise the script will just use pip. Not catastrophic, but using both conda and pip is probably not a great plan. If any of the packages are already installed, the package manager will attempt to update them. If they are already at their most recent level, it will do nothing.

If you're running Linux, navigate to the installers directory in the terminal and type ./RunThis_Linux.sh. This script should behave the same way: ask you for the name of the installer and proceed to install the packages.

Command Prompt Superpowers

If you prefer to install the packages manually, type the following commands into the command prompt, in no particular order:

  • conda install jupyter
  • conda install numpy
  • conda install scipy
  • conda install pandas

Or just type one command conda install jupyter, numpy, scipy, pandas

If all of these modules installed fine, you are all set to start with the notebooks for this workshop. You can check your installation by using the conda install <module name> command again. If the most recent version of a module is already installed, you will get a message saying All requested packages already installed..

Now, how do you actually download all these scripts and notebooks to your computer?

4. Running the IPython notebook

In the command prompt, navigate to the folder where you have cloned/downloaded this repository. Navigate to the scripts directory. Run a dir command to see if the IPython notebook exists in the scripts directory. If it does exist, and it should, type the following command:

jupyter notebook tutorial.ipynb

You will see a bunch of time-stamped commands start flowing in the command prompt. Your default browser (I use Firefox) will fire up and the notebook will open in a new tab. Do not close the command prompt where you started the notebook while you are working on it. This will shut down the python server for your notebook and it will no longer work.

Each notebook is like an interactive front-end to an instance of python.exe running in the background (python 3 in this tutorial). You can also use other backends: R, Julia, or Python 2.

Extras: Editing Python Scripts

So you think Jupyter notebooks are for kids and grandmothers? Then try your hand at editing python files (.py). You can save the Jupyter notebook as a python script and run it in the command line directly (expert level), and edit it in an IDE like Spyder or PyCharm. A python file is a simple text file - so you can edit it in any basic editor like Notepad++ or Atom.