User Tools

Site Tools


Working with Python

This page will tell you how to select a python distribution and start (and exit!) the python interpreter

After reading this page, you can read the JYP's recommended steps for learning python for really working with python

Note: the former and outdated version (before the massive usage of conda) is still available for reference

Where to start

In order to start working with Python, you need to have a Python distribution installed on your local computer or on the remote Linux server(s) you work on. A distribution provides a Python interpreter, and Python extensions (aka Python modules or packages). You may have several distributions installed on your computer and you need to know how to initialize them, and which one you are using at a given time (type which python on Linux to determine where the python executable is located)

If you are using a Linux computer or a Mac, you should already have a default python installed. The following example shows where the python interpreter is installed on the obelix LSCE servers (if it's in /usr/bin, it's the default python) and which version it is (example below: version 2.7.5 compiled in April 2019)

# Which is the current python (e.g. where is it located)?
 > which python

# Where is it coming from ('rpm' works on a RedHat-like Linux machine)?
 > rpm -qf /usr/bin/python

# You also get some information when you start the interpreter
 > python
Python 2.7.5 (default, Apr  9 2019, 14:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Ultra quick-start on the LSCE servers


  1. Start a terminal on an obelix server (more info)
  2. Type python to access the default Python 2 interpreter available on the servers…
  3. …or follow the steps below to use the more complete CDAT distribution maintained by JYP.
    Remember that you can exit the interpreter by typing CTRL-D (or quit() or exit())
    1. Determine if you are using a bash or tcsh shell (all the new LSCE accounts use the bash shell), then type the following command to initialize conda (conda helps you manage your python environment)
      • In a bash shell: source ~jypeter/
      • In a tcsh shell: source ~jypeter/.conda3_jyp.csh
    2. Choose which flavor of Python you want by typing the activation command:
      • Python 2.7.x: conda activate cdatm_py2
      • Python 3.x: conda activate cdatm_py3
    3. Type python to start the interpreter
    4. Note: if you will have to use python regularly, you should add the source line above to your .cshrc /.login file (tcsh users) or .bashrc/.profile (bash users)
      • Do not add the conda activate cdatm_pyN line to the shell config files, because this will create potential side-effects!
        Only type the activation command in the terminal(s) where you will need to use this specific version of Python


 >ssh obelix
Last login: Mon Jun  3 08:49:53 2019 from somewhere
bash-4.2$ which python
bash-4.2$ source ~jypeter/
bash-4.2$ which python
bash-4.2$ conda activate cdatm_py2
(cdatm_py2) bash-4.2$ which python
(cdatm_py2) bash-4.2$ python
Python 2.7.15 | packaged by conda-forge | (default, Feb 28 2019, 04:00:11)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello!')
>>>   # Type CTRL-D to exit the python interpreter

Useful keyboard shortcuts

Key Effect
CTRL-D Exit the interpreter
↑ and ↓ Go to previous/next line(s)
CTRL-A Go to the beginning of the line
CTRL-E Go to the end of the line
CTRL-K Erase from the cursor to the end of the line
CTRL-U Erase from the beginning of the line to the cursor
TAB x 2 Do some TAB-completion (context dependent)
e.g. a = np.cumTABTAB
CTRL-C Interrupt a running script
CTRL-Z Suspend the interpreter and go back to the shell
Do not forget to go back to the interpreter with fg
or to kill it (with jobs and kill %NN)

Executing a python script

Note: Python is an interpreted language and we speak of Python scripts rather than Python programs.

  • python: start the interpreter and start working interactively
  • python execute and exit
  • python -i script: execute and stay in the interpreter (-i = Interactive)

Type man python if you want to see what other command line options are available

Stand-alone script

You don't have to explicitly call the python interpreter, if the interpreter is specified in a #! shebang comment on the first line of the script with, and the script has its execution bit set (chmod +x

If you have a file with the following content in a directory…

#!/usr/bin/env python

import sys

script_name = sys.argv[0]

print('Hello world, I am the ' + script_name + ' script')

# The end

…and if you are in the same directory and have initialized the Python distribution you want, you can then run the script the following way:

 > chmod +x

 > ls -l
-rwxr-xr-x [...]

 > ./
Hello world, I am the ./ script

What next?

  1. Read the rest of this page to get a better understanding of what you have learned in this section, and use Python more efficiently
  2. Learn Python by reading what you need on the JYP's recommended steps for learning python page

Python distributions available for LSCE users

This section will help you choose a distribution in the big Python ecosystem (many distributions, python version 2.7.* or 3.*, …) on some of the servers used by LSCE users. You should use a distribution that is already available near your data (e.g. do the computation on a server near your data, do not move/duplicate the data!) and try to identify who is maintaining it, if you need help or additional packages.

Only install a distribution yourself if you need it on your local computer (desktop or laptop), or if you need to install some modules that can't be installed by the contacts listed below. A python distribution will require several Gb of disk space, so do not install it in your backed up home directory!

You can use either Python 2 or Python 3. Most packages are now available in both versions, but you should make sure that the most important package/s you need is/are available in the selected Python version. You can check the differences between both versions and try to write scripts that will work in both versions!

LSCE distribution

  • Contact: the LSCE system administrators (
  • Where: obelix interactive servers and obelix cluster at LSCE
  • Initialization type: module based + conda
  • What's installed: type conda list after initializing the LSCE distribution
 > module avail
4ARTIC/3.6         grib_api/1.14      netcdf/3           python/2.7.5
batch_env          grib_api/1.14.0    netcdf/4           python/3.6
glost/0.3.1        ncview/2.1.7       python/2.7

 > module load python/2.7

 > which python

 > python
Python 2.7.15 |Anaconda, Inc.| (default, Oct 10 2018, 21:32:13)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.


CDAT (Community Data Analysis Tools) is a powerful and complete front-end to a rich set of visual-data exploration and analysis capabilities well suited for climate data analysis problems. CDAT is recommended by JYP.

CDAT is available for Mac, Linux and Windows 10 (Windows 10 + Windows Subsystem for Linux, and Ubuntu).

  • Contact: Jean-Yves Peterschmitt (JYP) @ LSCE
  • Where: obelix interactive servers and cluster at LSCE, ciclad interactive servers and cluster at IPSL, irene @ TGCC
  • Initialization type: conda based or module based
  • What's installed: type conda list after initializing a specific CDAT distribution

CDAT versions maintained by JYP

The following versions are maintained by JYP, on the Linux servers where LSCE users have accounts

CDAT version JYP
Availability? Available packages Installation notes
8.2.1 19 3.8.8 LSCE Default CDAT 8.2.1 packages
Extra packages
8.2.1 notes
8.1 18 2.7.15
LSCE, ciclad Default CDAT 8.1 packages
Extra packages
8.1 notes

Read the Ultra quick-start on the LSCE servers above

Note: on the ciclad cluster, use source ~jypmce/ to initialize conda


Note: TGCC also supports its own TGCC distribution, that may be more up-to-date, if you don't need specific CDAT modules

CDAT 8.0 is installed at TGCC and can be initialized with:

  • Python 2: module load cdat
  • Python 3: module load flavor/cdat/python3 cdat

Note: if you get an error when importing cdms2 or vcs it means that either you have forgotten to initialize CDAT, or that something went wrong during the initialization. In both cases, you are either still using the default python installed on your system, or another (non-CDAT) python distribution!

$ python -c 'import cdms2, vcs'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named cdms2

# Am I using the correct python distribution?
$ which python

TGCC distribution

# Get the default version of the Python based modules
$ module avail -t -d | egrep '(python|cdat)'

$ module load python
load module python/2.7.14 (Python)

$ which python

$ python
Python 2.7.14 (default, Jan 11 2018, 16:43:59)
[GCC 4.8.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.


This is the recommended Python distribution/environment. It is available for Windows, Mac and Linux

Anaconda is a distribution provided by Continuum Analytics. It is similar to EDM

Note: Anaconda provides and uses conda for its installation. Since CDAT is also installed and maintained with conda, you can read the Installing and maintaining UV-CDAT with conda page for more information, even if you are not going to use CDAT

Enthought Deployment Manager (EDM)

This was previously called Enthought Python Distribution (EPD) and then Enthought Canopy

Enthought Deployment Manager (EDM) is Enthought’s mechanism to deliver scientific software applications and development environments

There are native installers for Windows (.msi), Mac OS X (.pkg), RHEL/Fedora (.rpm), and Debian/Ubuntu (.deb)


ipython interpreter

The ipython interpreter provides more options and commands than the standard python interpreter, but takes more time to start. If you are going to develop by starting and exiting the interpreter many times, it's faster to use the standard interpreter

Starting ipython: ipython

ipython notebook

FIXME Add a link to the new notebook page

Jupyter Notebook for Beginners: A Tutorial

The ipython notebook is a way to interact with python (and other supported interpreted languages) inside a web browser. You can mix cells with python commands, cells with the output of the python commands (possibly graphics generated by the commands), and text (using some wiki-like rich text format). This interactive web page, aka notebook, can be saved in a my_notebook.ipynb file and re-used later (e.g. the notebook provided in the introduction to Python, part 1).

Starting the notebook server: ipython notebook

Warning! When you start the notebook server, you will start a python process and a web browser, and a new python process will be started each time you open a new notebook.

Please make sure that you shutdown cleanly each notebook and the server when you are finished, in order not to clutter the local computer or remote server with lots of python processes (especially a server shared by many users!).

You may want to use the 'top' command in order to monitor what is happening

[ PMIP3 Wiki Home ] - [ Help! ] - [ Wiki syntax ]

other/python/starting.txt · Last modified: 2021/09/22 13:32 by jypeter