This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
guide:python [2020/08/04 15:22] agill [User Package Installation via pip3 and virtualenv] |
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/ | ||
| + | chpc/ | ||
| + | chpc/ | ||
| + | chpc/ | ||
| + | chpc/ | ||
| + | |||
| + | > To check the version of Python provided by each, load the module (after purging any already loaded modules) and then run '' | ||
| + | |||
| + | login1:~$ module purge | ||
| + | login1:~$ module load chpc/ | ||
| + | login1:~$ python3 --version | ||
| + | Python 3.7.4 | ||
| + | login1:~$ module purge | ||
| + | login1:~$ module load chpc/ | ||
| + | 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 '' | 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 '' | ||
| Line 10: | Line 32: | ||
| ==== User Package Installation via pip3 and virtualenv ==== | ==== 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, | Because CHPC users don't have permission to modify the python installations, | ||
| - | '' | + | |
| **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 " | 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: | 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: | ||
| - | '' | + | |
| + | | ||
| 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:// | ||
| - | As an alternative, | + | 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. | ||
| - | To create a virtual environment called *myenv*, just cd to the place where you want the virtual environment to live (eg / | ||
| - | '' | ||
| 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 / | ||
| + | |||
| + | > 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 === | ==== User Package Installation with Anaconda === | ||
| Line 63: | Line 103: | ||
| 6. Activate the environment | 6. Activate the environment | ||
| conda activate / | conda activate / | ||
| - | You don't have to use " | + | 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: | 7. You can now install whatever packages you need, that are not installed already; for instance, for rpy2, type: | ||
| Line 92: | Line 134: | ||
| 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). | 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/ | ||