Introduction à Python
adapté du travail de J.R. Johansson (robert@riken.jp) http://dml.riken.jp/~rob/
Installation
Linux
Sous Ubuntu Linux:
$ sudo apt-get install python ipython ipython-notebook
$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sympy
$ sudo apt-get install spyder
MacOS X
Anaconda CE
Enthought Python Distribution. EPD commercial mais gratuit pour une utilisation académique.
Macports : http://www.macports.org
$ sudo port install py27-ipython +pyside+notebook+parallel+scientific
$ sudo port install py27-scipy py27-matplotlib py27-sympy
$ sudo port install py27-spyder
Pour choisir sa version de Python:
$ sudo port select python python27
$ sudo port select ipython ipython27
Fink : http://www.finkproject.org/
$ sudo fink install python27 ipython-py27 numpy-py27 matplotlib-py27 scipy-py27 sympy-py27
$ sudo fink install spyder-mac-py27
Windows
Python(x,y) (recommandé)
Anaconda CE
Enthought Python Distribution. EPD commercial mais gratuit pour une utilisation académique.
Remarque
EPD et Anaconda CE sont aussi disponibles sous Linux
Lancer un programme Python
Un fichier python termine par ".py":
mon_programme.py
Toutes les lignes d'un fichier Python sont excécutées sauf les lignes qui commencent par # qui sont des commentaires.
Pour lancer le programme depuis une ligne de commande ou un terminal:
$ python mon_programme.py
Sous UNIX (Linux / Mac OS) il est courant d'ajouter le chemin vers l'interpréteur python sur la première ligne du fichier:
#!/usr/bin/env python
Cela permet de lancer un progamme directement:
$ mon_programme.py
Exemple:
In [1]: ls scripts/hello-world.py
In [2]: cat scripts/hello-world.py
scripts/hello-world.py*