Installing Python

The easiest way to install python (and some related data science toolkits) is to install Anaconda.

1. Anaconda

Anaconda is created by Continuum Analytics, and it is a Python distribution that comes preinstalled with lots of useful python libraries for data science. Installing ananconda enables you to have a functional python environment alongside with many tools for coding data science / machine learning projects.

2. Step by step installation

Let us install Anaconda, python and Jupyter Notebook

STEP 1 : Download & Install Anaconda

image-8.png

image-3.png

STEP 2 : Install Jupyter Notebook (and eventually Spyder)

Jupyter notebook is a novel IDE to produce easy-to-read reports with text, equations, code and results (called a notebook). This is what is used here!. In a nutshell, a notebook is sequence of cells that contain Python commands with comments. For some useful shortcuts, see Help > Keyboard Shortcuts. As usual Let us now print Hello world! as an initiation ritual (just be sure to have a functional python environment!).

image-5.png

Remark: since Python is a scripting language, there are several ways to use this language. The main ones are detailed below.

STEP 3 : print hello world! with Jupyter Notebook

image-6.png

image-7.png

STEP 3b (OPTIONAL) : print hello world! with command line or Spyder

Command line

In a shell, execute:

$ python

Then, start using it:

>>> print("hello world!")

Press CTRL+D or type:

>>> quit()

to exit.

If your code is written in a file script.py, you can run it from a shell with:

$ python script.py

or in Python with:

>>> execfile('script.py')

Spyder

Spyder is an IDE that shows both an editor and a Python shell. It is an efficient tool for developping and testing codes.

In particular feature, it enables to run only part of the script while keeping the previous results (variable states) in memory.

To run a script, you can edit it and press F5. If you want to execute only a selection of it, select the part of interest and press F9.