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 [2019/04/26 07:35]
jypeter Added Ultra quick-start on the LSCE servers
other:python:starting [2022/09/28 13:46]
jypeter [CDAT]
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>​
  
Line 12: Line 12:
 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) 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)+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 30: Line 30:
 </​code>​ </​code>​
  
-===== Ultra quick-start on the LSCE servers =====+===== Ultra quick-start on the interactive ​LSCE servers =====
  
 ==== Initialization ==== ==== Initialization ====
  
-  - Start a terminal on an //obelix// server +  - Start a 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 or follow the steps below for a more advanced ​distribution. Remember that **you can exit the interpreter by typing CTRL-D** (or ''​quit()''​ or ''​exit()''​) +  - Type ''​python''​ to access the //default Python 2// interpreter ​available on the servers... 
-    - Determine if you are using a [[other:​newppl:​starting#​which_shell_are_you_using|bash or tcsh shell]], then type the following command to initialize python +  - ...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()''​) 
-      ​In a //bash// shell: ''​source ~jypeter/​.conda3_jyp.sh''​ +    - 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 //tcsh// shell: ''​source ~jypeter/​.conda3_jyp.csh''​+      ​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 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
  
-===== Python distributions available for LSCE users =====+=== Example ​===
  
-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 usersYou should use a distribution that is already available near your data (e.gdo 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.+<​code>​ >ssh obelix 
 +Last login: Mon Jun  3 08:49:53 2019 from somewhere 
 +bash-4.2$ which python 
 +/​usr/​bin/​python 
 +bash-4.2$ source ~jypeter/.conda3_jyp.sh 
 +bash-4.2$ which python 
 +/​usr/​bin/​python 
 +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 
 +(cdatm_py2bash-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!'​) 
 +hello! 
 +>>> ​  # Type CTRL-D to exit the python interpreter 
 +</​code>​
  
-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 a backed up //home// directory!+==== Useful keyboard shortcuts ====
  
-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 [[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!+^  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''​) ​ |
  
-==== LSCE distribution ​====+==== Executing a python script ​====
  
-  * Contactthe LSCE system administrators ([[help-lsce@lsce.ipsl.fr]]) +NotePython is an [[https://en.wikipedia.org/wiki/Interpreted_language|interpreted language]] and we speak of //Python scripts// rather than //Python programs//.
-  * Where: //obelix// interactive servers and 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+
  
-<​code>​ +  * ''​python'':​ start the interpreter and start working interactively 
- > module avail +  * ''​python script.py'':​ execute ​//script.py// and **exit** 
-[...] +  * ''​python -i script'':​ execute //script.py// and **stay in the interpreter** (''​-i''​ = //**I**nteractive//)
-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+Type ''​man ​python''​ if you want to see what other command line options are available
  
- > which python +==== Stand-alone script ====
-/​usr/​local/​install/​python-2.7/​bin/​python+
  
- > ​python +You don't have to explicitly call the python ​interpreterif the interpreter is specified in a ''#​!'' ​[[https://en.wikipedia.org/​wiki/​Shebang_%28Unix%29|shebang comment]] on **the first line of the script** withand the script has its //execution bit// set (''​chmod +x my_script.py''​). ​
-Python 2.7.15 |AnacondaInc.| (default, Oct 10 2018, 21:32:13) +
-[GCC 7.3.0] on linux2 +
-Type "​help",​ "​copyright"​"​credits"​ or "​license"​ for more information. +
->>>​ +
-</code>+
  
-==== TGCC distribution ====+If you have a ''​basic_script.py''​ file with the following content in a directory... 
 +<​code>​ 
 +#​!/​usr/​bin/​env python
  
-  * Contact: the TGCC hotline ([[hotline.tgcc@cea.fr]]) +import sys
-  * Where: CEA TGCC +
-  * Initialization type: [[other:​newppl:​starting#​using_module_to_access_optional_programs|module based]] +
-  * What's installed: it depends...+
  
-<​code>#​ Get the default version of the Python based modules +script_name = sys.argv[0]
-$ 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)+
  
-$ module load python +print('Hello world, I am the ' + script_name + ' script'​)
-[...] +
-load module python/​2.7.14 ​(Python)+
  
-$ which python +# The end</code>
-/ccc/​products/​python-2.7.14/​intel--17.0.4.196__openmpi--2.0.2/​default/​bin/​python+
  
-$ python +...and if you are in the same directory and have initialized the Python distribution you wantyou can then run the script the following way:
-Python 2.7.14 (defaultJan 11 2018, 16:43:59) +
-[GCC 4.8.5] on linux2 +
-Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. +
->>>​ +
-</​code>​+
  
-==== CDAT ====+<​code>​ > chmod +x basic_script.py
  
-[[https://​uvcdat.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 problems, and is recommended by JYP.+ > ls -l basic_script.py 
 +-rwxr-xr-x ​[...basic_script.py
  
-CDAT is **available for MacLinux and Windows 10 (Windows 10 + [[other:​win10wsl|Windows Subsystem for Linux, and Ubuntu]])**.+ > ./​basic_script.py 
 +Hello worldI am the ./​basic_script.py script 
 +</​code>​
  
-  * Contact: Jean-Yves Peterschmitt (//JYP//) @ LSCE +==== What next? ====
-  * 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+
  
-=== CDAT versions maintained ​by JYP ===+  - Read the rest of this page to get a better understanding of what you have learned in this section, and use Python more efficiently 
 +  - Learn Python ​by reading what you need on the [[other:​python:​jyp_steps|JYP's recommended steps for learning python]] page
  
-The following versions are maintained by JYP, on the Linux servers where LSCE users have accounts 
  
-^  CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Available packages ^  Installation notes  ^ +===== Using the LSCE jupyterhub server =====
-|  **8.1** ​ |  18  |  2.7.15\\ 3.6.7  |  ​LSCE, ciclad ​ |  {{ :​other:​uvcdat:​cdat_conda:​cdat-8.1_py2_list_190307.txt |Default CDAT packages}}\\ [[other:​uvcdat:​cdat_conda:​cdat_8_1#​extra_packages_list|Extra packages]] ​ |  [[other:​uvcdat:​cdat_conda:​cdat_8_1|8.1 notes]] ​ |+
  
-=== CDAT at TGCC ===+The [[https://​intranet.lsce.ipsl.fr/​informatique/​en/​jupyter/​index.php|LSCE jupyterhub notebook server]] is available for users with a LSCE Linux account:  
 +  * from a computer on the LSCE wired network: https://​jupyter.lsce.ipsl.fr/​ 
 +  * 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/​
  
-CDAT **8.0** is installed at TGCC and can be initialized with: +==== Using a non-standard kernel ====
-  * Python 2: ''​module load cdat''​ +
-  * Python 3: ''​module load flavor/​cdat/​python3 cdat''​+
  
-=== The basics of CDAT initialization ===+Note: a //kernel// is a specific python environment/​distribution
  
-The way you initialize CDAT depends on: +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
-  * which **server** you want to use it on +
-  * which **shell** you are using in your terminals: ​//tcsh// or other shells +
-    * Read [[other:newppl:​starting#which_shell_are_you_using|Which shell are you using?]] if you are not sure +
-    * Warning: the shell in a (batch) script may be different from your interactive shell! +
-  * which **version** of CDAT you want to use...+
  
-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 initialization. In both cases, you are either still using the default python installed on your system, or another (non-CDAT) python distribution!+The steps below show how to add a specific [[other:python:​starting#​cdat|CDAT environment]] kernelbut can be easily adapted for using other kernels
  
-<​code>​$ python ​-c '​import cdms2vcs' +  ​Initialize your (favorite) Python environment in a terminaland (as usualcheck which Python executable you are using\\ ​<code> >which python 
-Traceback ​(most recent call last)+/​usr/​bin/​python
-  File "<string>", line 1, in <module+
-ImportError:​ No module named cdms2+
  
-# Am I using the correct python distribution?​ + >​source ~jypeter/​.conda3_21-02_jyp.csh 
-$ which python + >conda activate cdatm_py3
-/​usr/​bin/​python</​code>+
  
-=== conda-based versions ​of 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 [[other:​uvcdat:cdat_conda:​|UV-CDAT 2.8.0 and later]] +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
  
-Note: if you need to maintain a **local** version on **your** machine, you can read [[other:uvcdat:conda_notes|Installing and maintaining CDAT with conda]] and the [[other:uvcdat:​cdat_conda:​index#​versions|versions specific notes]].+ >​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 =====
  
-== Configuring ​.bashrc ==+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.
  
-You should **add** the following line at the end of your ''​~/​.bashrc''​ configuration file (create the ''​~/​.bashrc''​ file if it does not exist yet). This will basically make sure that your shell can find the ''​conda''​ executable it needs for initializing CDAT, and define a ''​wp''​ alias that you can use to find where the ''​python''​ executable is located+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!
  
-^  Server ​ ^  Line to add to ''​.bashrc'' ​ ^ +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 versionYou 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!
-|  **LSCE** ​ | ''​source ~jypeter/.conda_jyp.sh''​\\ \\ Note:​{{ ​:​other:​python:​conda_jyp.txt |conda_jyp}} content | +
-|  **ciclad** ​ | ''​source ~jypmce/​.conda_jyp.sh'' ​|+
  
 +==== LSCE distribution ====
  
-Notewhen you add the specified line to your ''​bashrc''​ file, you will then always get the python supplied by conda, instead of the system'​s ​python, when you use ''​bash''​. If you don't like this permanent behavior, just type ''​source ~jyp_login_on_this_server/​.conda_jyp.sh'' ​in the bash shell where you want to use conda+CDAT, rather than adding it to the ''​.bashrc''​ file...+  * 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
  
-== Initializing CDAT ==+<​code>​ 
 +$ module -t avail 
 +[...] 
 +python/​2.7 
 +python/​2.7.5 
 +python/​2-ramces 
 +python/3 
 +python/​3.9 
 +python/​4artic 
 +python/​esmpy 
 +python/​intel 
 +[...]
  
-<WRAP center round tip 60%> +$ module load python/3.9
-When you initialize CDAT, it will be available only in the **current** window/shellIn the other windows, you still get whatever your default python is. This should minimize potential side-effects +
-</​WRAP>​+
  
-  - If [[other:​newppl:​starting#​which_shell_are_you_using|your shell]] is not //bash//, start a bash shell by typing ''​bash''​+$ which python 
 +/usr/local/​install/​python-3.9/bin/python
  
-    * You can later go back to your previous shell by typing ''​exit''​ or ''​CTRL-D''​ +$ python 
-  - Activate the //conda environment//​ that uses the version of UV-CDAT you want to use +Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
-    * ''​source activate conda_env_name''​ +[GCC 7.5.0] :: Anaconda, Inc. on linux 
-    * Use the table below to determine which environments are available ​on which server +Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. 
-  - Use CDAT !+>>>​ 
 +</​code>​
  
-^  UV-CDAT version ​ ^  Server ​ ^  Environment name\\ and activation line  ^  Packages\\ (''​conda list''​) ​ ^ +==== CDAT ====
-|  [[:​other:​uvcdat:​cdat_conda:​cdat_2_8_0|2.8.0]] ​ |  **LSCE**\\ **ciclad** ​ |**cdatm14** (''​source activate cdatm14''​) ​ |  {{ :​other:​uvcdat:​cdat_conda:​conda_list_lsce_cdatm14_170310.txt |cdatm14 installed packages}} ​ | +
-|  [[:​other:​uvcdat:​cdat_conda:​cdat_2_10|2.10]] ​ |  **LSCE** ​ |**cdatm15** (''​source activate cdatm15''​) ​ |  {{ :​other:​uvcdat:​cdat_conda:​uvcdat-2.10_list_170721.txt |cdatm14 installed packages}} ​ | +
-|  **cdatm** will always point to the latest stable version ​ |||| +
-|  //latest stable version// ​ |  **LSCE** ​ |**cdatm** (''​source activate cdatm''​) ​ |  ''​conda list'' ​ |+
  
 +[[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 problems. CDAT is **recommended by JYP**.
  
 +CDAT is **available for Mac, Linux and Windows 10 (Windows 10 + [[other:​win10wsl|Windows Subsystem for Linux, and Ubuntu]])**.
  
-==== Canopy ====+  * 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 
 +  * What's installed: type ''​conda list''​ after initializing a specific CDAT distribution
  
-[[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]]. It used to be called EPD (//​Enthought Python Distribution//​)+=== CDAT versions maintained ​by JYP ===
  
-Canopy is **available for Windows, Mac 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+The following versions ​are maintained by JYPon the Linux servers where LSCE users have accounts
  
 +^  CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Available packages ^  Installation notes  ^
 +|  **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]] ​ |
 +|  **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]] ​ |
  
-==== Anaconda ====+== Initialization ​==
  
-[[https://www.continuum.io/​why-anaconda|Anaconda]] is a distribution similar to [[#canopy]] provided by [[https://www.continuum.io/|Continuum Analytics]].+Read the [[https://wiki.lsce.ipsl.fr/pmip3/doku.php/other:​python:​starting#​ultra_quick-start_on_the_interactive_lsce_servers|Ultra quick-start on the LSCE servers]] above
  
-Anaconda is **available for WindowsMac and Linux**+Note: on the ciclad clusteruse ''​source ~jypmce/​.conda3_jyp.sh''​ to initialize conda
  
-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+=== CDAT at TGCC ===
  
-===== Launching Python =====+Note: TGCC also supports its own [[#​tgcc_distribution|TGCC distribution]],​ that may be more up-to-date, if you don't need specific CDAT modules
  
-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).+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''​
  
-Remember that on Linux/Mac you can check which python you are using by typing ''​which python''​!+=== A common CDAT-related error ===
  
-==== Useful keyboard shortcuts ====+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!
  
-^  Key  ^  Effect ​ ^ +<​code>​$ python ​-c '​import cdms2, vcs' 
-|  **CTRL-D**  |  Exit the interpreter ​ | +Traceback ​(most recent call last): 
-|  **↑ and ↓**  |  Go to previous/​next line(s | +  ​File "<​string>", ​line 1, in <​module>​ 
- **CTRL-A** ​ |  Go to the beginning of the line  | +ImportError:​ No module named cdms2
-|  **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''​) ​ |+
  
-==== Stand-alone script ====+# Am I using the correct python distribution?​ 
 +$ which python 
 +/​usr/​bin/​python</​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 its execution bit set (''​chmod +x my_script.py''​). ​+==== TGCC distribution ====
  
-<​code>​ +  * Contact: the TGCC hotline ([[hotline.tgcc@cea.fr]]) 
-jypeter@asterix1 - ...jypeter - 54 >cat basic_script.py +  * Where: CEA TGCC 
-#​!/​usr/​bin/​env python+  * Initialization type: [[other:​newppl:​starting#​using_module_to_access_optional_programs|module based]] 
 +  * What's installed: it depends...
  
-import sys+<​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)
  
-script_name = sys.argv[0]+$ module load python 
 +[...] 
 +load module python/​2.7.14 (Python)
  
-print('​Hello world, I am the ' + script_name + ' script'​) +$ which python 
- +/​ccc/​products/​python-2.7.14/​intel--17.0.4.196__openmpi--2.0.2/​default/​bin/​python
-# The end +
- +
-jypeter@asterix1 ​- ...jypeter ​55 >chmod +x basic_script.py+
  
-ypeter@asterix1 - ...jypeter - 56 ># Type here what is required to initialize the distribution you want +$ python 
- +Python 2.7.14 (default, Jan 11 2018, 16:43:59) 
-jypeter@asterix1 - ...jypeter - 57 >​./​basic_script.py +[GCC 4.8.5] on linux2 
-Hello worldI am the ./​basic_script.py script+Type "​help"​"​copyright",​ "​credits"​ or "​license"​ for more information. 
 +>>>​
 </​code>​ </​code>​
  
-==== Standard interpreter ==== 
  
-  * ''​python'':​ start the interpreter +===== ipython =====
-  * ''​python script.py'':​ execute //​script.py//​ and **exit** +
-  * ''​python -i script'':​ execute //​script.py//​ and **stay in the interpreter** (''​-i'' ​//​**I**nteractive//​) +
- +
-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 269: Line 306:
   * [[https://​damontallen.github.io/​IPython-quick-ref-sheets/​|Ipython-quick-ref-sheets]]   * [[https://​damontallen.github.io/​IPython-quick-ref-sheets/​|Ipython-quick-ref-sheets]]
  
 +
 +==== LSCE jupyter notebook server ====
 +
 +The different Python distributions available on the LSCE servers (interactive servers and cluster) can also be used on the [[https://​intranet.lsce.ipsl.fr/​informatique/​en/​jupyter/​index.php|LSCE jupyter notebook server]]:
 +  * If your computer is on the LSCE wired network
 +  * Or if you are using the [[https://​intranet.lsce.ipsl.fr/​informatique/​fr/​vpn-forticlient.php|LSCE VPN]]
 ==== ipython notebook ==== ==== ipython notebook ====
  
-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]]).+<WRAP center round tip 60%> 
 +If you want to use ipython notebooks at LSCE, you should **use the [[other:​python:​starting#​lsce_jupyter_notebook_server|LSCE notebook server]]** rather than trying to use (and probably overloading) the interactive servers! 
 +</​WRAP>​ 
 + 
 + 
 +<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]]).
  
 Starting the notebook server: ''​ipython notebook''​ Starting the notebook server: ''​ipython notebook''​
  
-<note warning>​**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.+<note warning> 
 +  * **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 ​server shared by many users!).+  * 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 ​an interactive ​server shared by many users!).
  
-You may want to [[other:​newppl:​starting#​determining_the_load_of_a_linux_server|use the '​top'​ command]] in order to monitor what is happening</​note>​+  * You may want to [[other:​newppl:​starting#​determining_the_load_of_a_linux_server|use the '​top'​ command]] in order to monitor what is happening ​on the interactive server where you are using your notebook server 
 +</​note>​
  
 /* standard page footer */ /* standard page footer */
other/python/starting.txt · Last modified: 2023/05/17 08:10 by jypeter