6. Usage of Python¶
6.1. About using Python¶
In this system, pyenv can be installed in the user’s environment by executing the following script. Python version control is possible with pyenv. Please see below for details.
6.2. Install pyenv¶
Execute the following command to install pyenv on super and gpu.
bash /work/app/pyenv/pyenv-setup.bash
6.3. Backing up the pyenv environment from the previous system¶
If you used the pyenv environment in the previous system, you will need to back up the old pyenv environment. Please back up the old environment with the command below.
mv ~/.pyenv-super ~/.pyenv-super.old
mv ~/.pyenv-gpu ~/.pyenv-gpu.old
6.4. Setting environment variables¶
The pyenv environment variable file is located in /work/app/pyenv/bash_env. If you want to load the pyenv environment by default, run the command below.
echo "source /work/app/pyenv/bash_env" >> ~/.bash_profile
6.5. Operational check¶
After installing pyenv, log out from the front end node once, log in again, and then execute the following command.
pyenv --version
pyenv 1.2.8-5-gec9fb549 ←The version may be different.
6.6. Basic usage¶
・Install Python using pyenv
pyenv install --list ←View available Python versions
・・・・
pyenv install 3.7.8 ←Install Python 3.7.8
・Switch python versions
pyenv versions ←Check the installed version
* system (set by /home/userA/.pyenv/version)
3.7.8
pyenv global 3.7.8 ←Switch to Python 3.7.8
python --version
You can also add packages using pip. For more detailed usage, please check the pyenv documentation etc.
6.7. Execution method¶
Execute Python programs with high load on compute nodes instead of front end nodes.
・A example for interactive mode
userA@gpu2:~> qsub -I -q IP_001
qsub: waiting for job 70568.gpu1 to start
qsub: job 70568.gpu1 ready
-bash-4.2$ python
Python 3.7.8 (default, Mar 25 2021, 09:54:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>>
You may also execute as a job script.
・A example for job script
#!/bin/sh
#PBS -l select=1
#PBS -q CA_001
#PBS -N sample
cd $PBS_O_WORKDIR
python program.py