This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
guide:python [2014/04/22 16:50] wikiadmin |
guide:python [2022/06/13 11:58] (current) wikiadmin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Python | + | ====== Python ====== |
| + | There are a number of python versions installed on Lengau compiled with either gcc or the intel compiler, including Python 2.7.11 to 2.7.15, Python 3.5-3.7 and anaconda installs for Python 2 and 3. | ||
| + | Use this command to get a full list: | ||
| + | module avail chpc/python | ||
| - | A fairly complete python 2.6.5 installation is available on both the login and compute nodes, at | + | Note that the modules including anaconda are more recent |
| - | '' | + | chpc/python/anaconda/3-2019.10 |
| + | chpc/ | ||
| + | chpc/python/ | ||
| + | chpc/python/ | ||
| + | chpc/ | ||
| - | I recommend you invoke your python scripts | + | > To check the version of Python provided |
| - | /opt/gridware/python2.6.5/bin/python /export/home/ | + | |
| + | login1:~$ module load chpc/python/anaconda/3-2019.10 | ||
| + | login1:~$ python3 --version | ||
| + | Python 3.7.4 | ||
| + | login1:~$ module purge | ||
| + | login1:~$ module load chpc/python/anaconda/3-2021.11 | ||
| + | login1:~$ python3 --version | ||
| + | Python 3.9.7 | ||
| + | login1: | ||
| - | Modules included with this are :- | ||
| - | | numpy scipy | Comprehensive scientific processing for python | | ||
| - | | PyNGL | Scientific visualisation | | ||
| - | | tables | ||
| - | | mpl_toolkits matplotlib | ||
| - | | Crypto | ||
| - | | OpenSSL | ||
| - | | IPython | ||
| - | | PyNIO | NetCDF file reader / writer | | ||
| - | | Polygon | ||
| - | | ANN | kdtree-based Approximate Nearest Neighbour routines | | ||
| - | | h5py | interface to the HDF5 binary data format [see notes below] | | ||
| - | Most of these modules | + | All python |
| - | ====Notes==== | + | To use tensorflow, the anaconda module for python3 is also recommended. |
| - | ===h5py=== | + | ==== User Package Installation via pip3 and virtualenv |
| + | //The following will **not** work with the anaconda modules, see below if you want to use those.// | ||
| + | |||
| + | Because CHPC users don't have permission to modify the python installations, | ||
| + | pip install --user PySomeProject | ||
| + | **This can only be done from a node with internet access - for example chpcviz1 or chpclic1 (but not a compute node).** | ||
| + | Of course, you will also need to replace " | ||
| + | |||
| + | By default this installs to the .local directory within your home directory. This can be a problem if you need to install a lot of python packages, as your home directory can only accommodate 15GB. If you think you are likely to run out of space, you should rather specify a directory on lustre, as follows: | ||
| + | |||
| + | pip install --install-option=" | ||
| + | |||
| + | As before, replace USERNAME and PySomeProject with appropriate values. | ||
| + | You can find more information on user installs in the [[https:// | ||
| + | |||
| + | As an alternative, | ||
| + | |||
| + | To create a virtual environment called //myenv//, just cd to the place where you want the virtual environment to live --- for example | ||
| + | |||
| + | <code bash> | ||
| + | cd / | ||
| + | </ | ||
| + | |||
| + | where '' | ||
| + | |||
| + | |||
| + | python3 -m venv myenv | ||
| + | |||
| + | You only need to do this once, to set up the virtual environment. | ||
| + | |||
| + | Then, to activate the virtual environment (which you will need to do whenever you use it - so put it in your submit-script or ~/.bashrc file): | ||
| + | |||
| + | source / | ||
| + | |||
| + | > Note the full path to the virtual environment is on your Lustre directory: ''/ | ||
| + | |||
| + | Again, there is more information in [[https:// | ||
| + | |||
| + | ==== User Package Installation with Anaconda === | ||
| + | Modules for anaconda version 2 and 3 are installed on lengau.To load these modules, use the following command (either from the command-line in an interactive session, or in a script: | ||
| + | module add chpc/ | ||
| + | or: | ||
| + | module add chpc/ | ||
| + | |||
| + | Using virtualenv with anaconda is not recommended. | ||
| + | However, Anaconda does include a similar functionality, | ||
| + | |||
| + | The following instructions to set up your virtual environment. | ||
| + | |||
| + | **YOU NEED ONLY DO THEM ONCE. Please replace // | ||
| + | |||
| + | 1. Log into lengau.chpc.ac.za | ||
| + | |||
| + | 2. '' | ||
| + | //Unlike the compute nodes, chpcviz1 and chpclic1 have a connection to the internet, which is needed here.// | ||
| + | |||
| + | 3. Load the appropriate anaconda module | ||
| + | module load chpc/ | ||
| + | |||
| + | You can substitute chpc/ | ||
| + | |||
| + | 4. Do the once-off initialisation for your shell: | ||
| + | conda init bash | ||
| + | You might have to log out and back in at this point to enable the | ||
| + | shell setup. | ||
| + | |||
| + | 5. Create a new conda environment: | ||
| + | conda create --prefix / | ||
| + | Change '' | ||
| + | |||
| + | 6. Activate the environment | ||
| + | conda activate / | ||
| + | You don't have to use " | ||
| + | eval " | ||
| + | |||
| + | |||
| + | 7. You can now install whatever packages you need, that are not installed already; for instance, for rpy2, type: | ||
| + | conda install rpy2 | ||
| + | |||
| + | 8. you can now type: | ||
| + | conda deactivate / | ||
| + | to exit the virtual environment. | ||
| + | |||
| + | |||
| + | Now, once you've done this, you can log out, and ready your job for submission from the login node. | ||
| + | |||
| + | **You must do the following in your job-submit script or your .bashrc file in your home directory**: | ||
| + | |||
| + | Put it all near the top of your script, but after the ''# | ||
| + | < | ||
| + | module add chpc/ | ||
| + | |||
| + | conda activate / | ||
| + | </ | ||
| + | and at the end: | ||
| + | < | ||
| + | conda deactivate / | ||
| + | </ | ||
| + | Then submit your script as normal with '' | ||
| + | |||
| + | |||
| + | if you ever need to install new Python packages, just repeat steps 1, 2, 3, 6, 7 and 8 from above. (omit 4 and 5). | ||
| + | |||
| + | |||
| + | ===conda bug=== | ||
| + | |||
| + | There is known bug inflicting some versions of conda. | ||
| + | |||
| + | source / | ||
| + | |||
| + | instead of '' | ||
| + | |||
| + | > Replace the above path ''/ | ||
| + | |||
| + | Remember that you can find the paths used by any module using the '' | ||
| + | |||
| + | module show chpc/ | ||
| - | The '' | ||