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/24 15:21]
jypeter [Python distributions available for LSCE users] Updated
other:python:starting [2019/05/17 08:56]
jypeter [Initialization] Improved
Line 5: Line 5:
 You can then read the [[jyp_steps|JYP'​s recommended steps for learning python]] for really working with python You can then 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 =====
Line 27: Line 29:
 >>>​ >>>​
 </​code>​ </​code>​
 +
 +===== Ultra quick-start on the LSCE servers =====
 +
 +==== Initialization ====
 +
 +  - Start a terminal on an //obelix// server
 +  - 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.\\ 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]], then type the following command to initialize //conda//
 +      * 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:
 +      * 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 this activation line in the terminals where you will need to use this specific version of Python
 +
 +==== 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.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''​) ​ |
 +
 +==== Executing a python script ====
 +
 +Note: Python is an [[https://​en.wikipedia.org/​wiki/​Interpreted_language|interpreted language]] and we speak of //Python scripts// rather than //Python programs//.
 +
 +  * ''​python'':​ start the interpreter and start working interactively
 +  * ''​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
 +
 +==== Stand-alone 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''​). ​
 +
 +If you have a ''​basic_script.py''​ file with the following content in a directory...
 +<​code>​
 +#​!/​usr/​bin/​env python
 +
 +import sys
 +
 +script_name = sys.argv[0]
 +
 +print('​Hello world, I am the ' + script_name + ' script'​)
 +
 +# The end</​code>​
 +
 +...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:
 +
 +<​code>​ > chmod +x basic_script.py
 +
 + > ls -l basic_script.py
 +-rwxr-xr-x [...] basic_script.py
 +
 + > ./​basic_script.py
 +Hello world, I am the ./​basic_script.py script
 +</​code>​
 +
 +==== What next? ====
 +
 +  - 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
  
 ===== Python distributions available for LSCE users ===== ===== 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.*, ...). 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.+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, or if you need to install some modules that can't be installed by the contacts listed below. A python distribution ​can require several Gb of disk space, so do not install it in a backed up //home// directory!+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!
  
-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 version. ​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-)+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!
  
 ==== LSCE distribution ==== ==== LSCE distribution ====
  
-Contact: the LSCE system administrators ([[help-lsce@lsce.ipsl.fr]])+  * Contact: the LSCE system administrators ([[help-lsce@lsce.ipsl.fr]]) 
 +  * 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>​ <​code>​
  > module avail  > module avail
 [...] [...]
-castem/12        ferret/6.9.5     hdf5/1.8.9       netcdf/4p        ​python/​2.7.5 ​    sun-java/7.0.45+4ARTIC/3.6         ​grib_api/1.14      ​netcdf/3           python/​2.7.5 
 +batch_env ​         grib_api/1.14.0    ​netcdf/​4 ​          ​python/​3.
 +[...] 
 +glost/​0.3.1 ​       ncview/​2.1.7 ​      ​python/​2.7
 [...] [...]
  
- > module load python/2.7.5+ > module load python/2.7
  
  > which python  > which python
-/​usr/​local/​install/​python-2.7.5/bin/python+/​usr/​local/​install/​python-2.7/​bin/​python
  
  > python  > python
-Python 2.7.(default, ​Sep 18 201315:47:43+Python 2.7.15 |Anaconda, Inc.| (default, ​Oct 10 201821:32:13
-[GCC 4.4.20120313 (Red Hat 4.4.7-3)] on linux2+[GCC 7.3.0] on linux2
 Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information.
 >>>​ >>>​
Line 60: Line 140:
 ==== TGCC distribution ==== ==== TGCC distribution ====
  
-Contact: the TGCC hotline ([[hotline.tgcc@cea.fr]])+  * 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...
  
-<​code>​ +<​code>​# Get the default version of the Python based modules 
-$ module avail +$ module avail -t -d | egrep '​(python|cdat)'​ 
-[...] +flavor/​cdat/​standard(default) 
-cmake/2.8.9(default) ​     hwloc/1.5                 ​netcdf-utils/4.3.3.1_hdf5 python/2.7.8              tix/8.4.3 +flavor/nest/​python2(default) 
-cmake/3.2.2               ​hwloc/​1.7.1(default) ​     ​octave/3.6.3              python/​3.3.2 ​             tk/8.5(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
 [...] [...]
- +load module python/2.7.14 (Python)
-$ module load python/​2.7.8 +
-load module python/2.7.(Python)+
  
 $ which python $ which python
-/usr/local/​ccc_python/2.7.8_201409/bin/python+/ccc/products/python-2.7.14/​intel--17.0.4.196__openmpi--2.0.2/​default/bin/python
  
 $ python $ python
-Python 2.7.(default, ​Aug 27 201417:50:16+Python 2.7.14 (default, ​Jan 11 201816:43:59
-[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2+[GCC 4.8.5] on linux2
 Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information. Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information.
 >>>​ >>>​
 </​code>​ </​code>​
  
-==== UV-CDAT ====+==== CDAT ====
  
-ContactJean-Yves Peterschmitt ​(//JYP//) @ LSCE+[[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.
  
-=== What is UV-CDAT? ===+CDAT is **available for Mac, Linux and Windows 10 (Windows 10 + [[other:​win10wsl|Windows Subsystem for Linux, and Ubuntu]])**.
  
-[[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.+  * ContactJean-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
  
-UV-CDAT is **available for Mac and Linux**.+=== CDAT versions maintained by JYP ===
  
-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**, ...+The following versions ​are maintained ​by JYPon the Linux servers where LSCE users have accounts
  
-**Extra packages** are listed: +^  CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Available packages ^  Installation notes  ^ 
-  * in the apropriate //​Installation notes// pages for CDAT>​=''​2.8.0''​ +|  ​**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]] ​ |
-  * on the [[other:​uvcdat:​extra|Extra packages ​installed in UV-CDAT by JYP]] page for CDAT%%<​=%%''​2.10''​+
  
-=== UV-CDAT versions maintained by JYP ===+=== CDAT at TGCC ===
  
-The following versions are maintained by JYP, on the Linux servers where LSCE users have accounts+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''​
  
-^  ​CDAT version ​ ^  JYP\\ version ​ ^  python\\ version ​ ^  Availability? ​ ^  Packages built by CDAT  ^  Installation notes  ^ +=== The basics of CDAT initialization ===
-|  **1.1.0** ​ |  08  |  2.7.3  |  LSCE, curie  |  n/a  |  [[other:​uvcdat:​installed#​section110|1.1.0 notes]] ​ | +
-|  **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: +The way you initialize CDAT depends on:
-  * For the conda based CDAT versions (>​=''​2.8.0''​),​ you can get the list of currently available packages by typing: ''​conda list''​ +
-  * For older CDAT versions (<​=''​2.1.0''​),​ 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''​ +
- +
-=== The basics of UV-CDAT initialization === +
- +
-The way you initialize ​UV-CDAT depends on:+
   * which **server** you want to use it on   * which **server** you want to use it on
   * which **shell** you are using in your terminals: //tcsh// or other shells   * 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     * 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!     * Warning: the shell in a (batch) script may be different from your interactive shell!
-  * which **version** of UV-CDAT you want to use... +  * which **version** of 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 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!+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!
  
 <​code>​$ python -c '​import cdms2, vcs' <​code>​$ python -c '​import cdms2, vcs'
Line 133: Line 215:
 /​usr/​bin/​python</​code>​ /​usr/​bin/​python</​code>​
  
-=== conda-based versions of UV-CDAT ===+=== conda-based versions of CDAT ===
  
 <WRAP center round important 60%> <WRAP center round important 60%>
Line 139: Line 221:
 </​WRAP>​ </​WRAP>​
  
-Note: if you need to maintain a **local** version on **your** machine, you can read [[other:​uvcdat:​conda_notes|Installing and maintaining ​UV-CDAT with conda]] and the [[other:​uvcdat:​cdat_conda:​index#​versions|versions specific notes]].+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]].
  
 == Configuring .bashrc == == Configuring .bashrc ==
Line 152: Line 234:
 Note: when 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... Note: when 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...
  
-== Initializing ​UV-CDAT ==+== Initializing CDAT ==
  
 <WRAP center round tip 60%> <WRAP center round tip 60%>
-When you initialize ​UV-CDAT, it will be available only in the **current** window/​shell. In the other windows, you still get whatever your default python is. This should minimize potential side-effects+When you initialize CDAT, it will be available only in the **current** window/​shell. In the other windows, you still get whatever your default python is. This should minimize potential side-effects
 </​WRAP>​ </​WRAP>​
  
   - If [[other:​newppl:​starting#​which_shell_are_you_using|your shell]] is not //bash//, start a bash shell by typing ''​bash''​   - If [[other:​newppl:​starting#​which_shell_are_you_using|your shell]] is not //bash//, start a bash shell by typing ''​bash''​
 +
     * You can later go back to your previous shell by typing ''​exit''​ or ''​CTRL-D''​     * You can later go back to your previous shell by typing ''​exit''​ or ''​CTRL-D''​
   - Activate the //conda environment//​ that uses the version of UV-CDAT you want to use   - Activate the //conda environment//​ that uses the version of UV-CDAT you want to use
Line 171: Line 254:
 |  //latest stable version// ​ |  **LSCE** ​ |**cdatm** (''​source activate cdatm''​) ​ |  ''​conda list'' ​ | |  //latest stable version// ​ |  **LSCE** ​ |**cdatm** (''​source activate cdatm''​) ​ |  ''​conda list'' ​ |
  
-=== Older versions of UV-CDAT === 
  
-<WRAP center round important 60%> 
-The steps detailed in this section are for **UV-CDAT ''​2.1.0''​ and earlier** 
-</​WRAP>​ 
- 
-== Initializing UV-CDAT for tcsh users == 
- 
-If you use **tcsh** as [[other:​newppl:​starting#​which_shell_are_you_using|your login shell]], you can define a ''​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: 
-  * type ''​cdatm''​ to initialize the default version of UV-CDAT 
-  * type ''​cdatm %%--%%config //​CONFIG_NAME//''​ to initialize a 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 
-/​usr/​bin/​python 
- 
- > cdatm 
-** CDAT '​uv-1.5.1'​ initialized! 
-** If you have problems with this installation,​ 
-** it is maintained by: Jean-Yves Peterschmitt - LSCE 
- 
- > which python 
-/​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. 
- 
-|  **LSCE** ​ | ''​alias cdatm '​source ~jypeter/​CDAT/​Install/​cdat_multi/​cdat_multi.login ~jypeter/​CDAT/​Install/​cdat_multi'''​ | 
-|  **ciclad** ​ | ''​alias cdatm '​source ~jypmce/​CDAT/​Install/​cdat_multi/​cdat_multi.login ~jypmce/​CDAT/​Install/​cdat_multi'''​| 
-|  **curie** ​ | ''​alias cdatm '​source ~p25jype/​CDAT/​Install/​cdat_multi/​cdat_multi.login ~p25jype/​CDAT/​Install/​cdat_multi'''​ | 
-|  **All** servers ​ | ''​alias wp 'which python''​ | 
- 
-== Initializing UV-CDAT in any kind of shell, or in a batch script == 
- 
-You first need to know where the ''​python''​ program provided by UV-CDAT is installed, something like ''/​path/​to/​UV-CDAT/​bin/​python''​ 
- 
-Then, all you need to do in order to initialize UV-CDAT is to //source// the ''​setup_runtime''​ file appropriate for [[other:​newppl:​starting#​which_shell_are_you_using|your shell]]: 
-  * tcsh: type ''​source /​path/​to/​UV-CDAT/​bin/​setup_runtime**.csh**''​ 
-  * bash, sh/ksh: type ''​source /​path/​to/​UV-CDAT/​bin/​setup_runtime**.sh**''​ 
- 
-The table below lists, for each server and version, the path where you can find the //​setup_runtime//​ files 
- 
-^  Server ​ ^  CDAT\\ version ​ ^  JYP\\ version ​ ^  Path  ^ 
-|  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 shell, you need to do the following (you only need the //source// line. The other lines are optional, just for checking that the initialization was OK) 
- 
-<​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 
- 
-bash-4.1$ which python 
-/​home/​share/​unix_files/​cdat/​versions/​cdat_install_uv-2.1.0_x86_64_gcc4_13/​bin/​python 
- 
-bash-4.1$ python -c '​import cdms2, vcs' 
-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: 
-  * tcsh: add 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'''​ 
-  * bash: add 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'''​ 
- 
-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 
-<​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 
-mypython=`which python` 
-echo 
-echo -e "This script will use the following python: $mypython\n\n"</​code>​ 
  
 ==== Canopy ==== ==== Canopy ====
Line 258: Line 271:
 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 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
  
-===== Launching Python ​===== +===== ipython ​=====
- +
-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). +
- +
-Remember that on Linux/Mac you can check which python you are using by typing ''​which python''​! +
- +
-==== 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.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 ==== +
- +
-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''​).  +
- +
-<​code>​ +
-jypeter@asterix1 - ...jypeter - 54 >cat basic_script.py +
-#​!/​usr/​bin/​env python +
- +
-import sys +
- +
-script_name = sys.argv[0] +
- +
-print('​Hello world, I am the ' + script_name + ' script'​) +
- +
-# 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 +
- +
-jypeter@asterix1 - ...jypeter - 57 >​./​basic_script.py +
-Hello world, I am the ./​basic_script.py script +
-</​code>​ +
- +
-==== Standard interpreter ==== +
- +
-  * ''​python'':​ start the interpreter +
-  * ''​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 ====
other/python/starting.txt · Last modified: 2024/05/30 13:41 by jypeter