Getting started

Python Install

Anaconda

Is is strongly advised to install Python by using Anaconda:

  • Ready to go Python, with the main libraries installed (Numpy, Scipy, Matplotlib)

  • Possibility to create multiple environments with different versions of Python and packages (conda).

In practice:

  • Download the distribution corresponding to your system (cf. Download)

  • Install it in a place where you have read and write access.

Running Python

Python console

To run Python in normal mode, type in a terminal:

python
../_images/console.png

Interactive Python console

To run Python in interactive mode, type in a terminal:

ipython
../_images/ipython.png

Spyder (IDE)

To run the Python IDE, type in a terminal:

spyder &
../_images/spyder.png

Jupyter Notebook

To run the Jupyter Notebook, type in a terminal:

jupyter notebook &
../_images/notebook.png

Running scripts

Open a text editor and type in:

import sys

# my first program (comment)
print('hello ', sys.argv)

Save as hello.py

Running using python

From the terminal type:

python hello.py arg1 arg2 arg3

You should see:

hello  ['hello.py', 'arg1', 'arg2', 'arg3']
Note: The sys.argv statements returns the list of arguments, with the 1st element the name of the script.

Running using ipython

Open ipython from the terminal, then type:

run hello.py arg1 arg2 arg3

To check the environment, type whos. You should see:

In [2]: whos
Variable   Type      Data/Info
------------------------------
sys        module    <module 'sys' (built-in)>

Running from Spyder

Open spyder, open the file and click on the Run -> Configuration per file menu. Add arguments to the program as follows:

../_images/args_spyder.png

Then, click on the Run file button to run all the program or the Run selection button to run the current line

Run file button:

../_images/run_file.png

Run selection button:

../_images/run_sel.png