User Tools

Site Tools


other:python:starting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
other:python:starting [2017/03/08 17:00]
jypeter
other:python:starting [2022/08/11 09:37]
jypeter [Anaconda] Updated
Line 1: Line 1:
 ====== Working with Python ====== ====== Working with Python ======
  
-<note tip>This page will tell you how to select a python distribution and start (and exit!) the python interpreter+<note tip>This page will tell you how to select a //python distribution// and start (and exit!) the python interpreter
  
-You can then read the [[jyp_steps|JYP'​s recommended steps for learning python]] for really working with python+After reading this page, you can read the [[jyp_steps|JYP'​s recommended steps for learning python]] for really working with python
 </​note>​ </​note>​
 +
 +Note: the former and **outdated** version (before the massive usage of //conda//) is still [[other:​python:​starting_170810|available for reference]]
  
 ===== Where to start ===== ===== Where to start =====
  
-In order to begin using 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//​). 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)+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 //asterix// LSCE server ​(if it's in ''/​usr/​bin'',​ it's the default python) and which version it is (version //2.6.6// compiled in May 2015)+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)
  
 <​code>#​ Which is the current python (e.g. where is it located)? <​code>#​ Which is the current python (e.g. where is it located)?
Line 18: Line 20:
 # Where is it coming from ('​rpm'​ works on a RedHat-like Linux machine)? # Where is it coming from ('​rpm'​ works on a RedHat-like Linux machine)?
  > rpm -qf /​usr/​bin/​python  > rpm -qf /​usr/​bin/​python
-python-2.6.6-64.el6.x86_64+python-2.7.5-77.el7_6.x86_64
  
-# You also get some info when you start the interpreter+# You also get some information ​when you start the interpreter
  > python  > python
-Python 2.6.(r266:84292May 22 201508:34:51+Python 2.7.(defaultApr  9 201914:30:50
-[GCC 4.4.7 20120313 ​(Red Hat 4.4.7-15)] on linux2+[GCC 4.8.5 20150623 ​(Red Hat 4.8.5-36)] on linux2
 Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information.
 >>>​ >>>​
 </​code>​ </​code>​
  
-===== Python distributions available for LSCE users =====+===== Ultra quick-start on the interactive ​LSCE servers ​=====
  
-This section will help you choose a distribution in the big Python ecosystem (many distributions,​ python version 2.7.* or 3.*, ...). 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 extra packages.+==== Initialization ====
  
-Only install ​a distribution ​yourself if you need it on your local computer, ​or if you need to install some modules that can't be installed ​by the contacts listed belowpython ​distribution can require several Gb of disk spaceso do not install it in a backed up //home// directory!+  - Start terminal on an //obelix// server ([[https://​wiki.lsce.ipsl.fr/​pmip3/​doku.php/​other:​newppl:​starting#​which_linux_servers_should_you_use|more info]]) 
 +  - Type ''​python''​ to access the //default Python 2// interpreter available on the servers... 
 +  - ...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()''​) 
 +    - Determine ​if you are using a [[other:​newppl:​starting#​which_shell_are_you_using|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/​.conda3_jyp.sh''​ 
 +      * In a //tcsh// shell: ''​source ~jypeter/​.conda3_jyp.csh''​ 
 +    - 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''​ 
 +    - Type ''​python''​ to start the interpreter 
 +    - Note: if you will have to use python regularlyyou 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
  
-We suggest that you **use Python 2 rather than Python 3**. Or you can check the [[https://​wiki.lsce.ipsl.fr/​pmip3/​doku.php/​other:​python:​jyp_steps#​python_27_vs_python_3|differences between both versions]] and try to write scripts that will work in both versions! 8-)+=== Example ===
  
-==== LSCE distribution ==== +<​code>​ >ssh obelix 
- +Last login: Mon Jun  3 08:49:53 2019 from somewhere 
-Contact: the LSCE system administrators ([[help-lsce@lsce.ipsl.fr]]) +bash-4.2$ which python 
- +/usr/bin/python 
-<​code>​ +bash-4.2$ source ~jypeter/.conda3_jyp.sh 
- module avail +bash-4.2which python 
-[...] +/usr/bin/python 
-castem/12        ferret/6.9.5     hdf5/1.8.9       ​netcdf/​4p ​       python/2.7.5     ​sun-java/7.0.45 +bash-4.2$ conda activate cdatm_py2 
-[...] +(cdatm_py2) bash-4.2$ which python 
- +/​home/​share/​unix_files/​cdat/​miniconda3/​envs/​cdatm_py2/​bin/​python 
- > module load python/2.7.5 +(cdatm_py2) bash-4.2$ ​python 
- +Python 2.7.15 | packaged by conda-forge | (default, ​Feb 28 201904:00:11
- > ​which python +[GCC 7.3.0] on linux2
-/usr/local/​install/python-2.7.5/​bin/​python +
- +
- > ​python +
-Python 2.7.(default, ​Sep 18 201315:47:43+
-[GCC 4.4.20120313 (Red Hat 4.4.7-3)] on linux2+
 Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information.
->>>​+>>> ​print('​hello!'​) 
 +hello! 
 +>>> ​  # Type CTRL-D to exit the python interpreter
 </​code>​ </​code>​
  
-==== TGCC distribution ​====+==== Useful keyboard shortcuts ​====
  
-Contact: ​the TGCC hotline ​([[hotline.tgcc@cea.fr]])+^  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.cum**TABTAB**'' ​ | 
 +|  **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''​ |
  
-<​code>​ +==== Executing a python ​script ====
-$ module avail +
-[...] +
-cmake/​2.8.9(default) ​     hwloc/​1.5 ​                ​netcdf-utils/​4.3.3.1_hdf5 ​python/​2.7.8 ​             tix/8.4.3 +
-cmake/​3.2.2 ​              ​hwloc/​1.7.1(default) ​     octave/​3.6.3 ​             python/​3.3.2 ​             tk/​8.5(default) +
-[...]+
  
-$ module load python/2.7.8 +Note: Python is an [[https://en.wikipedia.org/​wiki/​Interpreted_language|interpreted language]] and we speak of //Python ​scripts// rather than //Python programs//.
-load module python/2.7.8 (Python)+
  
-$ which python +  * ''​python'':​ start the interpreter and start working interactively 
-/usr/local/ccc_python/2.7.8_201409/bin/python+  * ''​python script.py'':​ execute ​//script.py// and **exit** 
 +  * ''​python -i script'':​ execute //script.py// and **stay in the interpreter** (''​-i''​ = //​**I**nteractive//​)
  
-$ python +Type ''​man python''​ if you want to see what other command line options are available
-Python 2.7.8 (default, Aug 27 2014, 17:50:16) +
-[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 +
-Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. +
->>>​ +
-</​code>​+
  
-==== UV-CDAT ====+==== Stand-alone script ​====
  
-ContactJean-Yves Peterschmitt (//JYP//) @ LSCE+You don't have to explicitly call the python interpreter,​ if the interpreter is specified in a ''#​!''​ [[https://en.wikipedia.org/wiki/Shebang_%28Unix%29|shebang comment]] on **the first line of the script** with, and the script has its //execution bit// set (''​chmod +x my_script.py''​)
  
-=== What is UV-CDAT? ===+If you have a ''​basic_script.py''​ file with the following content in a directory... 
 +<​code>​ 
 +#​!/​usr/​bin/​env python
  
-[[http://​uv-cdat.llnl.gov/​|UV-CDAT]] (//​Ultrascale Visualization - Climate Data Analysis Tools//) is a python distribution developed specifically for the climate scientists, and is recommended by JYP.+import sys
  
-UV-CDAT is **available for Mac and Linux**.+script_name = sys.argv[0]
  
-You can find out which **standard packages** are installed in the //Packages built by CDAT// column below. UV-CDAT also provides some **specific packages** that you will not find in other python distributions:​ **cdms2**, **cdutil**, **cdtime**, **genutil**,​ **vcs**, **cmor**, ...+print('​Hello world, I am the ' + script_name + ' script'​)
  
-**Extra packages** are listed: +# The end</code>
-  * on the [[other:​uvcdat:​extra|Extra packages installed in UV-CDAT by JYP]] page for CDAT%%<=%%''​2.10''​ +
-  * in the apropriate ​//​Installation notes// pages for CDAT>=''​2.8.0''​+
  
-=== UV-CDAT versions maintained by JYP ===+...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:
  
-The following versions are maintained by JYP, on the Linux servers where LSCE users have accounts+<​code>​ > chmod +x basic_script.py
  
- CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Packages built by CDAT  ^  Installation notes  ^ + > ls -l basic_script.py 
-|  **1.1.0**  |  08  |  2.7.3  |  LSCE, curie  |  n/a  |  [[other:​uvcdat:​installed#​section110|1.1.0 notes]] ​ | +-rwxr-xr-x [...] basic_script.py
-|  **1.5.1** ​ |  10  |  2.7.4  |  LSCE, ciclad ​ |  {{:​other:​python:​cdat-1.5.1_jyp-10_build_info.txt}} ​ |  [[other:​uvcdat:​installed#​section151|1.5.1 notes]] ​ | +
-|  **2.1.0** ​ |  13  |  2.7.8  |  LSCE, ciclad ​ |  {{:​other:​python:​cdat-2.1.0_jyp-13_build_info.txt}} ​ |  [[other:​uvcdat:​installed#​section210|2.1.0 notes]]  | +
-|  **2.4.0**  |  //Not installed// ​ ||||| +
-|  **2.8.0** ​ |  14  |  2.7.12 ​ |  LSCE  |  {{:​other:​uvcdat:​uvcdat-2.8.0_install_dry_with-forge_160221.txt}} ​ |  [[:​other:​uvcdat:​cdat_conda:​cdat_2_8_0|2.8.0 notes]] ​ |+
  
-Notes: + ./basic_script.py 
-  * The ''​cdat-VVV_jyp-NNN_build_info.txt''​ files have been generated with\\ ''​cd ​/my_build_directory_path;​ cat build_info.txt | sort > cdat-VVV_JYP-NNN_build_info.txt''​ +Hello world, I am the ./​basic_script.py script 
-  * For the conda based CDAT versions (>​=''​2.8.0''​),​ you can get the list of currently available packages by typing: ''​conda list''​+</​code>​
  
-=== The basics of UV-CDAT initialization ​===+==== What next? ====
  
-The way you initialize UV-CDAT depends on: +  ​Read the rest of this page to get better understanding ​of what you have learned in this section, and use Python more efficiently 
-  * which **server** you want to use it +  Learn Python by reading what you need on the [[other:​python:​jyp_steps|JYP'​s recommended steps for learning python]] page
-  * which **shell** you are using in your terminals: //tcsh// or other shells +
-    * Warning: the shell in (batch) script may be different from your interactive shell! +
-  * which **version** ​of UV-CDAT ​you want to use... +
-    * Note: You should use the most recent version of UV-CDAT available on a given server, unless you have a good reason to use an older version (e.g. if you need to use the //old-style vcs// of version 1.5.1).+
  
-Note: if you are not sure which shell is running in your terminals, you can find out the following way 
  
-<​code>​ +===== Using the LSCE jupyterhub server =====
-# Somewhere with tcsh +
- > echo $SHELL +
- /​bin/​tcsh+
  
-# Somewhere else with bash +The [[https://​intranet.lsce.ipsl.fr/​informatique/​en/​jupyter/​index.php|LSCE jupyterhub notebook server]] is available for users with a LSCE Linux account: ​ 
- $ echo $SHELL +  * from a computer on the LSCE wired network: https://jupyter.lsce.ipsl.fr/​ 
- /bin/bash +  * from other computers: start the [[https://​intranet.lsce.ipsl.fr/​informatique/​fr/​vpn-forticlient.php#​vpnlsce|LSCE VPN]] before opening https://​jupyter.lsce.ipsl.fr/
-</code>+
  
-Note: if you get an error when importing //cdms2// or //vcs// it means that either you have forgotten to initialize UV-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 python distribution!+==== Using a non-standard kernel ====
  
-<​code>​$ ​python ​-c '​import cdms2, vcs' +Note: a //kernel// is a specific ​python ​environment/​distribution
-Traceback (most recent call last): +
-  File "<​string>",​ line 1, in <​module>​ +
-ImportError:​ No module named cdms2+
  
-$ which python +The LSCE jupyterhub server can be used to open //Notebooks// using pre-configured Python or R //​kernels//​. It is also possible to define additional per-user kernels by adding [[https://​jupyter-client.readthedocs.io/​en/​stable/​kernels.html#​kernel-specs|kernel configuration directories]] in the user's home directory
-/usr/bin/python</code>+
  
-=== conda-based versions of UV-CDAT ===+The steps below show how to add a specific [[other:​python:​starting#​cdat|CDAT environment]] kernel, but can be easily adapted for using other kernels
  
-<WRAP center round important 60%> +  ​Initialize your (favorite) Python environment in a terminal, ​and (as usual) check which Python executable you are using\\ ​<code>which python 
-The steps detailed in this section are for **UV-CDAT 2.8.0 and later** +/​usr/​bin/​python
-</WRAP>+
  
 + >​source ~jypeter/​.conda3_21-02_jyp.csh
 + >​conda activate cdatm_py3
  
-=== Older versions ​of UV-CDAT ===+(cdatm_py3) ​ >which python 
 +/​home/​share/​unix_files/​cdat/​miniconda3_21-02/​envs/​cdatm_py3/​bin/​python</​code>​ 
 +  - Determine where the kernel configuration files of the **active** python are located\\ <​code>​ >jupyter kernelspec list 
 +Available kernels: 
 +  python3 ​    /​home/​share/​unix_files/​cdat/​miniconda3_21-02/​envs/​cdatm19_nompi_py3/​share/​jupyter/​kernels/​python3</​code>​ 
 +  - Copy the existing kernel directory that you have found to your home directory. You can use the existing kernel name, or use a new kernel name (using only ASCII letters, numbers, ​ ''​-''​ hyphen, ''​.''​ period and ''​_''​ underscore)\\ <​code>​ >cp -pr /​home/​share/​unix_files/​cdat/​miniconda3_21-02/​envs/​cdatm19_nompi_py3/​share/​jupyter/​kernels/​python3 ~/​.local/​share/​jupyter/​kernels 
 + >​cp -pr /​home/​share/​unix_files/​cdat/​miniconda3_21-02/​envs/​cdatm19_nompi_py3/​share/​jupyter/​kernels/​python3 ~/​.local/​share/​jupyter/​kernels/​my_favorite_kernel
  
-<WRAP center round important 60%+ >​ls ~/​.local/​share/​jupyter/​kernels/​ 
-The steps detailed in this section are for **UV-CDAT 2.1.0 and earlier** +my_favorite_kernel/ ​   python3/ 
-</WRAP>+</code
 +  Check that the ''​kernelspec list''​ command now finds the new kernel(s)\\ <​code>​ >jupyter kernelspec list 
 +Available kernels: 
 +  my_favorite_kernel ​   your_home_dir/​.local/​share/​jupyter/​kernels/​my_favorite_kernel 
 +  ​python3 ​              ​your_home_dir/​.local/​share/​jupyter/​kernels/​python3</code> 
 +  - You can optionally change the value of the ''​display_name''​ parameter in the ''​kernel.json''​ configuration file if you want to customize the name that will appear in the jupyterhub kernel menus\\ <​code>​ >ls your_home_dir/​.local/​share/​jupyter/​kernels/​my_favorite_kernel 
 +kernel.json ​ logo-32x32.png ​ logo-64x64.png
  
-== Initializing UV-CDAT ​for tcsh users ==+ >​cat your_home_dir/​.local/​share/​jupyter/​kernels/​my_favorite_kernel/​kernel.json 
 +
 + "​argv":​ [ 
 +  "/​home/​share/​unix_files/​cdat/​miniconda3_21-02/​envs/​cdatm19_nompi_py3/​bin/​python",​ 
 +  "​-m",​ 
 +  "​ipykernel_launcher",​ 
 +  "​-f",​ 
 +  "​{connection_file}"​ 
 + ], 
 + "​display_name":​ "My favorite Python kernel",​ 
 + "​language":​ "​python"​ 
 +</​code>​ 
 +  - refresh the https://​jupyter.lsce.ipsl.fr/​ page and the new kernel(s) should appear in the kernels'​ related menus 
 +===== Python distributions available ​for LSCE users =====
  
-If you use **tcsh** as your login shell, you can define ​''​cdatm''​ alias on all the IPSL servers on which UV-CDAT is installed ​(see details below)and move easily from one version of UV-CDAT to another: +This section will help you choose ​distribution in the big Python ecosystem ​(many distributionspython ​version ​2.7.* or 3.*, ...) on some of the servers used by LSCE users. You should use distribution that is already available near your data (e.g. do the computation on a server near your datado not move/​duplicate the data!) and try to identify who is maintaining itif you need help or additional packages.
-  * type ''​cdatm''​ to initialize ​the default version of UV-CDAT +
-  * type ''​cdatm %%--%%config //​CONFIG_NAME//''​ to initialize ​specific version +
-    * You can find the allowed values of //​CONFIG_NAME// ​(e.g. ''​LSCE_10''​''​LSCE_13''​, ...) in one of the tables below+
  
-<​code>​ > which python +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!
-/usr/bin/python+
  
- > cdatm +You can use either //Python 2// or //Python 3//Most packages are now available in both versionsbut you should make sure that the most important package/s you need is/are available in the selected Python version. You can check the [[https://​wiki.lsce.ipsl.fr/​pmip3/​doku.php/​other:​python:​jyp_steps#​python_27_vs_python_3|differences between both versions]] and try to write scripts that will work in both versions!
-** CDAT 'uv-1.5.1' initialized! +
-** If you have problems with this installation, +
-** it is maintained byJean-Yves Peterschmitt - LSCE+
  
- > which python +==== LSCE distribution ====
-/​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-1.5.1_x86_64_gcc4_10/​bin/​python +
-</​code>​+
  
-You need to add the following line to the ''​.cshrc'' ​file in your home directory, in order to define the ''​cdatm'' alias. You can also define ​the simple ''​wp''​ alias, in order to always be able to determine quickly which python is initialized in the current terminal.+  * Contact: ​the LSCE system administrators ([[help-lsce@lsce.ipsl.fr]]) 
 +  * Where: //obelix// interactive servers and //obelix// cluster at LSCE 
 +  * Initialization type: [[other:​newppl:​starting#​using_module_to_access_optional_programs|module based]] + //conda// 
 +  * What's installed: type ''​conda list'' ​after initializing ​the LSCE distribution
  
-|  **LSCE** ​ | ''​alias cdatm '​source ~jypeter/CDAT/​Install/​cdat_multi/cdat_multi.login ~jypeter/CDAT/Install/​cdat_multi'''​ | +<​code>​ 
-|  **ciclad** ​ | ''​alias cdatm '​source ~jypmce/​CDAT/Install/​cdat_multi/​cdat_multi.login ~jypmce/CDAT/Install/​cdat_multi'''​| + > module avail 
-|  **curie** ​ | ''​alias cdatm '​source ~p25jype/CDAT/​Install/cdat_multi/​cdat_multi.login ~p25jype/​CDAT/Install/​cdat_multi'''​ | +[...] 
-|  **All** servers ​ | ''​alias wp 'which python''​ |+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 
 +[...]
  
-== Initializing UV-CDAT in any kind of shell, or in a batch script ==+ > module load python/2.7
  
-You first need to know where the ''​python''​ program provided by UV-CDAT is installed, something like ''​/path/to/UV-CDAT/bin/python''​+ > which python 
 +/usr/local/install/​python-2.7/bin/python
  
-Thenall you need to do in order to initialize UV-CDAT is to //source// the ''​setup_runtime''​ file appropriate for your shell+ > python 
-  * tcsh: type ''​source /​path/​to/​UV-CDAT/​bin/​setup_runtime.csh''​ +Python 2.7.15 |AnacondaInc.| (default, Oct 10 2018, 21:32:13) 
-  * bashsh/ksh: type ''​source /​path/​to/​UV-CDAT/​bin/​setup_runtime.sh''​+[GCC 7.3.0] on linux2 
 +Type "​help",​ "​copyright"​"​credits"​ or "​license"​ for more information. 
 +>>>​ 
 +</code>
  
-The table below lists, for each server and version, the path where you can find the //​setup_runtime//​ files+==== CDAT ====
  
-^  Server ​ ^  CDAT\\ version ​ ^  JYP\\ version ​ ^  Path  ^ +[[https://cdat.llnl.gov/|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 problemsCDAT is **recommended by JYP**.
-|  LSCE  |  1.1.0  |  LSCE_08 ​ |  ''​/home/​share/​unix_files/cdat/​versions/​cdat_install_uv-1.1.0_x86_64_gcc4_08/bin''  ​| +
-|  LSCE  |  1.5.1  |  LSCE_10 ​ |  ''​/home/share/unix_files/cdat/​versions/​cdat_install_uv-1.5.1_x86_64_gcc4_10/​bin'' ​ | +
-|  LSCE  |  2.1.0  |  LSCE_13 ​ |  ''/​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin'' ​ | +
-|  ciclad ​ |  1.5.1  |  ciclad_10-ng ​ |  ''/​data/​jypmce/​cdat/​versions/​cdat_install_uv-1.5.1_x86_64_gcc4_10-ng/​bin'' ​ | +
-|  ciclad ​ |  2.1.0  |  ciclad_13 ​ |  ''/​data/​jypmce/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin'' ​ | +
-|  curie  |  1.1.0  |  curie_08 ​ |  ''/​ccc/​work/​cont003/​dsm/​p25jype/​cdat/​versions/​cdat_install_uv-1.1.0_x86_64_gcc4_curie_08/​bin''​\\ ​**On curie**, you need to use **setup_cdat**.sh or **setup_cdat**.csh to initialize CDAT,\\ and also to load modules providing access to old librairies\\ ''​module load gnu/​4.6.3''​ and ''​module load qt/​4.8.6'' ​ |+
  
-Example: if you want to use UV-CDAT 2.1.0 at LSCE in a bash shellyou need to do the following ​(you only need the //source// line. The other lines are optionaljust for checking that the initialization was OK)+CDAT is **available for MacLinux and Windows 10 (Windows 10 + [[other:​win10wsl|Windows Subsystem for Linuxand Ubuntu]])**.
  
-<​code>​bash-4.1$ source ​/home/share/unix_files/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_13/bin/setup_runtime.sh+  * 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 [[other:​newppl:​starting#​using_module_to_access_optional_programs|module based]] 
 +  * What's installed: type ''​conda list''​ after initializing a specific CDAT distribution
  
-bash-4.1$ which python +=== CDAT versions ​maintained by JYP ===
-/​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin/​python+
  
-bash-4.1$ python -c '​import cdms2vcs' +The following versions are maintained by JYPon the Linux servers where LSCE users have accounts
-bash-4.1$</​code>​+
  
-You probably don't want to have to determine what you should type each time you want to use UV-CDAT in a window, so you should define a simple shortcut alias that you can type each time you need to initialize UV-CDAT. If, for example, you want to use UV-CDAT ​2.1.0 at LSCE+^  ​CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Available packages ^  Installation notes  ^ 
-  * tcshadd the following alias definitions to ''​~/​.cshrc''​\\ ''​alias cdat13 '​source /​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin/​setup_runtime.csh'''​\\  ​''​alias wp 'which python'''​ +|  **8.2.1**  |  19  |  3.8.8  |  ​LSCE  ​|  {{  ​:other:​uvcdat:​cdat_conda:​cdat_8.2.1_nompi_21-03-05.txt |Default CDAT 8.2.1 packages}}\\ [[other:​uvcdat:​cdat_conda:​cdat_8_2_1#​extra_packages_list|Extra packages]] ​  [[other:uvcdat:​cdat_conda:​cdat_8_2_1|8.2.1 notes]] ​ | 
-  * bashadd the following alias definition to ''​~/​.bashrc'',​ ''​~/​.profile''​ or ''​~/​.bash_profile''​ (whichever works for you, or read ''​man bash''​...)\\ ''​alias cdat13='​source /​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin/​setup_runtime.sh'''​\\ ''​alias wp='​which python'''​+|  **8.1**  |  18  |  2.7.15\\ 3.6.7  |  LSCE, ciclad ​ |  {{:​other:​uvcdat:​cdat_conda:​cdat-8.1_py2_list_190307.txt|Default CDAT 8.1 packages}}\\ [[other:​uvcdat:​cdat_conda:​cdat_8_1#​extra_packages_list|Extra packages]] ​ |  [[other:​uvcdat:​cdat_conda:​cdat_8_1|8.1 notes]] ​ |
  
-If you are going to use a UV-CDAT python script on a cluster or supercomputer,​ using some kind of batch system using a bash or ksh script, use the following lines before you run the python script +== Initialization ==
-<​code>​source /​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin/​setup_runtime.sh+
  
-# Check which python we will be using +Read the [[https://​wiki.lsce.ipsl.fr/​pmip3/​doku.php/​other:​python:​starting#​ultra_quick-start_on_the_lsce_servers|Ultra quick-start on the LSCE servers]] above
-mypython=`which python` +
-echo +
-echo -e "This script will use the following python$mypython\n\n"<​/code>+
  
-==== Canopy ====+Note: on the ciclad cluster, use ''​source ~jypmce/​.conda3_jyp.sh''​ to initialize conda
  
-[[https://​www.enthought.com/​products/​canopy/​|Enthought Canopy]] is //a Scientific and Analytic Python Deployment with Integrated Analysis Environment//​ provided by [[https://​www.enthought.com/​|Enthought]].+=== CDAT at TGCC ===
  
-It is **available for WindowsMac and Linux**. You can download the free //Canopy Express// ​that will already provide many extensions. If you are entitled ​to use //Canopy Academic//login from inside Canopy Express and download the extra modules ​you need+Note: TGCC also supports its own [[#​tgcc_distribution|TGCC distribution]], that may be more up-to-dateif 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''​
  
-==== Anaconda ====+=== A common CDAT-related error ===
  
-[[https://www.continuum.io/why-anaconda|Anaconda]] is a distribution similar to [[#canopy]] provided by [[https://www.continuum.io/|Continuum Analytics]].+Noteif 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 initializationIn both cases, you are either still using the default python installed on your system, or another (non-CDAT) python distribution!
  
-It is **available for WindowsMac and Linux**+<​code>​$ python -c '​import cdms2vcs' 
 +Traceback (most recent call last): 
 +  File "<​string>",​ line 1, in <​module>​ 
 +ImportError:​ No module named cdms2
  
-Note: Anaconda provides and uses ''​conda''​ for its installation. Since UV-CDAT is now also installed and maintained with ''​conda'',​ you can read the [[other:​uvcdat:​conda_notes|Installing and maintaining UV-CDAT with conda]] page for more information,​ even if you are not going to use UV-CDAT+# Am I using the correct python distribution?​ 
 +$ which python 
 +/​usr/​bin/​python</​code>​
  
-===== Launching Python =====+==== TGCC distribution ​====
  
-Once you have initialized ​the [[#some_python_distributions|python distribution]] you want to use, follow the instructions below to //start the interpreter from a shell// (on a Windows computer, you will have to start python from the //Start// menu or by clicking a shortcut on your desktop).+  * Contact: ​the TGCC hotline ([[hotline.tgcc@cea.fr]]) 
 +  * Where: CEA TGCC 
 +  * Initialization type: [[other:​newppl:​starting#using_module_to_access_optional_programs|module based]] 
 +  * What's installed: it depends...
  
-Remember that you can check which python ​you are using by typing ​''​which ​python''​!+<​code>#​ Get the default version of the Python based modules 
 +$ module avail -t -d | egrep '(python|cdat)' 
 +flavor/​cdat/​standard(default) 
 +flavor/​nest/​python2(default) 
 +flavor/​pytorch/​python2(default) 
 +flavor/​tensorflow/​gpu_python2(default) 
 +intelpython2/​2019.0(default) 
 +intelpython3/​2019.0(default) 
 +python/​2.7.14(default) 
 +python3/​3.6.4(default) 
 +cdat/​8.0(default)
  
-==== Useful keyboard shortcuts ====+$ module load python 
 +[...] 
 +load module python/​2.7.14 (Python)
  
-^  Key  ^  Effect ​ ^ +$ which python 
-|  **CTRL-D** ​ |  Exit the interpreter ​ | +/ccc/​products/​python-2.7.14/intel--17.0.4.196__openmpi--2.0.2/​default/​bin/​python
-|  **↑ 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  ​| ​ Do some TAB-completion (context dependent)\\ e.g''​a = np.cum**TABTAB**'' ​ | +
-|  **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''​) ​ |+
  
-==== Stand-alone script ====+$ 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. 
 +>>>​ 
 +</​code>​
  
-A python script is just like any other shell script. You don't have to explicitly call the python interpreter,​ if the interpreter is specified in a ''#​!''​ [[https://​en.wikipedia.org/​wiki/​Shebang_%28Unix%29|shebang comment]] on the first line of the script with, and the script has it's execution bit set.  
  
-<​code>​ +==== Anaconda ====
-jypeter@asterix1 - ...jypeter - 54 >cat basic_script.py +
-#​!/​usr/​bin/​env python+
  
-import sys+<note tip>This is the recommended (by JYP) Python distribution/​environment. It is **available for Windows, Mac and Linux**</​note>​
  
-script_name = sys.argv[0]+The [[https://​www.anaconda.com/​products/​distribution|Anaconda distribution]] is  provided by the [[https://​www.anaconda.com/​about-us|Anaconda]] company (that was [[https://​www.anaconda.com/​blog/​continuum-analytics-officially-becomes-anaconda|previously called Continuum Analytics]]). It is similar to [[#​enthought_deployment_manager_edm|EDM]], but probably more widely used than EDM
  
-print('​Hello world, I am the ' + script_name + ' script'​) 
  
-The end+Note: Anaconda provides and uses ''​conda''​ for its installation. Since [[#cdat|CDAT]] is also installed and maintained with ''​conda'',​ you can read the [[other:​uvcdat:​conda_notes|Installing and maintaining UV-CDAT with conda]] page for more information,​ even if you are not going to use CDAT
  
-jypeter@asterix1 - ...jypeter - 55 >chmod +x basic_script.py+==== Enthought Deployment Manager (EDM) ====
  
-ypeter@asterix1 - ...jypeter - 56 ># Type here what is required to initialize the distribution you want+<note tip>This was previously called //Enthought Python Distribution (EPD)// and then  //Enthought Canopy//</​note>
  
-jypeter@asterix1 - ...jypeter - 57 >./basic_script.py +[[https://www.enthought.com/enthought-deployment-manager/|Enthought Deployment Manager (EDM)]] is Enthought’s mechanism to deliver scientific software applications and development environments
-Hello world, I am the ./basic_script.py script +
-</code>+
  
-==== Standard interpreter ====+There are native installers for Windows (.msi), Mac OS X (.pkg), RHEL/Fedora (.rpm), and Debian/​Ubuntu (.deb)
  
-  * ''​python'':​ start the interpreter +===== ipython =====
-  * ''​python script.py'':​ execute //​script.py//​ and **exit** +
-  * ''​python -i script'':​ execute //​script.py//​ and **stay in the interpreter** +
- +
-Type ''​man python''​ if you want to see what other command line options are available+
  
 ==== ipython interpreter ==== ==== ipython interpreter ====
  
-The //ipython// interpreter provides more options and commands than the standard python interpreter,​ but takes more time to load. If you are going to develop by starting and exiting the interpreter many times, it's faster to use the standard 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''​ Starting ipython: ''​ipython''​
Line 299: Line 320:
  
 ==== ipython notebook ==== ==== ipython notebook ====
 +
 +<note warning>​FIXME Add a link to the new notebook page</​note>​
 +
 +[[https://​www.dataquest.io/​blog/​jupyter-notebook-tutorial/​|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 [[other:​python:​jyp_steps#​part_1|introduction to Python, part 1]]). 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 [[other:​python:​jyp_steps#​part_1|introduction to Python, part 1]]).
other/python/starting.txt · Last modified: 2024/05/30 13:41 by jypeter