User Tools

Site Tools


guide:python

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
guide:python [2020/09/08 16:10]
kevin [User Package Installation with Anaconda]
guide:python [2022/06/13 11:58] (current)
wikiadmin
Line 4: Line 4:
 Use this command to get a full list: Use this command to get a full list:
     module avail chpc/python     module avail chpc/python
 +
 +Note that the modules including anaconda are more recent and thus recommended over the plain Python modules, i.e., use one of:
 +
 +  chpc/python/anaconda/3-2019.10
 +  chpc/python/anaconda/3-2020.02
 +  chpc/python/anaconda/3-2020.11
 +  chpc/python/anaconda/3-2021.05
 +  chpc/python/anaconda/3-2021.11
 +
 +>  To check the version of Python provided by each, load the module (after purging any already loaded modules) and then run ''python --version'' For example (screen capture --- don't type in the ''login1:~$'', that's the shell prompt):
 +
 +  login1:~$ module purge
 +  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:~$ 
 +
 +
  
 All python modules should have mpi4py, numpy and scipy installed; however if matplotlib is required, please use anaconda (which also has the biggest range of 3rd-party python modules). The module ''chpc/python/3.5.2_gcc-6.2.0'' also has a working matplotlib installation. All python modules should have mpi4py, numpy and scipy installed; however if matplotlib is required, please use anaconda (which also has the biggest range of 3rd-party python modules). The module ''chpc/python/3.5.2_gcc-6.2.0'' also has a working matplotlib installation.
Line 13: Line 35:
  
 Because CHPC users don't have permission to modify the python installations, you will not be able to install libraries to the python installation. You can, however, install them to a different location using the --user flag when you run pip install or pip3 install(the latter for python3): Because CHPC users don't have permission to modify the python installations, you will not be able to install libraries to the python installation. You can, however, install them to a different location using the --user flag when you run pip install or pip3 install(the latter for python3):
-''pip install --user PySomeProject''+  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).** **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 "PySomeProject" with the name of the package that you want to install. Of course, you will also need to replace "PySomeProject" with the name of the package that you want to install.
Line 19: Line 41:
 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: 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="--prefix=/mnt/lustre/users/USERNAME/.local PySomeProject''+  pip install --install-option="--prefix=/mnt/lustre/users/USERNAME/.localPySomeProject
  
 As before, replace USERNAME and PySomeProject with appropriate values. As before, replace USERNAME and PySomeProject with appropriate values.
 You can find more information on user installs in the [[https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site|official python documentation]] and more information on pip user installs [[https://pip.pypa.io/en/latest/user_guide/#user-installs|here]]. You can find more information on user installs in the [[https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site|official python documentation]] and more information on pip user installs [[https://pip.pypa.io/en/latest/user_guide/#user-installs|here]].
  
-As an alternative, you can also set up a python virtual environment. This essentially gives you your own python installation which you can alter as you see fit. Again, it is perhaps best done in your lustre directory if a large number of python libraries will be installed.+As an alternative, you can also set up a python virtual environment. This essentially gives you your own python installation which you can alter as you see fit. Again, it is perhaps best done in your Lustre directory if a large number of python libraries will be installed.
  
-To create a virtual environment called //myenv//, just cd to the place where you want the virtual environment to live (eg. ''cd /mnt/luster/users/USERNAME''), and run the following command:+To create a virtual environment called //myenv//, just cd to the place where you want the virtual environment to live --- for example
  
-''python3 -m venv myenv''+<code bash> 
 +cd /mnt/lustre/users/USERNAME 
 +</code> 
 + 
 +where ''USERNAME'' is replace by __your__ cluster user name --- and run the following command: 
 + 
 + 
 +  python3 -m venv myenv
  
 You only need to do this once, to set up the virtual environment. You only need to do this once, to set up the virtual environment.
Line 34: Line 63:
 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): 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 /mnt/lustre/users/USERNAME/myenv/bin/activate''+  source /mnt/lustre/users/USERNAME/myenv/bin/activate 
 + 
 +> Note the full path to the virtual environment is on your Lustre directory: ''/mnt/lustre/users/USERNAME/myenv/''
  
 Again, there is more information in [[https://docs.python.org/3/tutorial/venv.html|the official python documentation]]. Again, there is more information in [[https://docs.python.org/3/tutorial/venv.html|the official python documentation]].
Line 72: Line 103:
 6. Activate the environment 6. Activate the environment
     conda activate /home/USERNAME/myenv     conda activate /home/USERNAME/myenv
-You don't have to use "myenv", just replace it consistently with whatever name you prefer for your virtual environment, ''myenv'' will work, though.+You don't have to use "myenv", just replace it consistently with whatever name you prefer for your virtual environment, ''myenv'' will work, though. To enable conda environments, add the following to your script before activating the environment. 
 +    eval "$(conda shell.bash hook)"  
  
 7. You can now install whatever packages you need, that are not installed already; for instance, for rpy2, type: 7. You can now install whatever packages you need, that are not installed already; for instance, for rpy2, type:
Line 112: Line 145:
 > Replace the above path ''/apps/chpc/chem/anaconda3-2019.10'' with the path to the Anaconda version you are actually using. > Replace the above path ''/apps/chpc/chem/anaconda3-2019.10'' with the path to the Anaconda version you are actually using.
  
 +Remember that you can find the paths used by any module using the ''module show'' command:
 +
 +    module show chpc/python/anaconda/3-2019.10
  
  
  
/app/dokuwiki/data/attic/guide/python.1599574255.txt.gz · Last modified: 2021/12/09 16:42 (external edit)