Warning! Python 2 has reached the end of life on January 2020, after many years of prior notifications. It is not supported in any way. Do not use it and do not ask about it.
It is not possible to provide a single, system-wide python installation because of various versions of packages, which can be conflicting. Thus the "system python" is installed for system tools rather then for users - if it fits your needs use it, but do not ask to install additional packages. The proper way to use python are user's virtual environments. They enable multiple, independent python installations, each with own set of packages.
There are two major methods to create the python virtual environment:
Below we present both methods tested on the chuck cluster.
cd /work/chuck/$USER wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.shIt comes with the most current version of python. For older versions check https://docs.conda.io/en/latest/miniconda.html
[[ -r ~/.bashrc ]] && source ~/.bashrc
Tip 4. If you do not want to automatically activate the default environment on each shell startup (which results in a small delay) execute this (recommended):
conda config --set auto_activate_base false
Test the installation. The changes made above will work in a new shells - open a new terminal and check installed packages:
conda list
Add conda-forge repository (it provides more and more recent versions of many packages)
conda config --add channels conda-forge
Create a new virtual environment
conda create -n myenv python=3 pandas matplotlib jupyter nb_conda
Activate the environment
conda activate myenv
To install additional packages, e.g. numpy use
conda install numpy
For details see the documentation: https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html#
Python 3 comes with virtual environment tool built-in (pyvenv).
Optional! If you need to compile specific python 3 version.
cd /work/chuck/$USER
mkdir -p .pythons
cd .pythons
wget https://www.python.org/ftp/python/3.4.5/Python-3.4.5.tgz
tar zxvf Python-3.4.5.tgz
cd Python-3.4.5
make clean
mkdir /work/chuck/$USER/.pythons/3.4
./configure --prefix=/work/chuck/$USER/.pythons/3.4
make -j4
make install
cd ..
rm -rf Python-3.4.5*
Now let's create a virtual environment.
cd /work/chuck/$USER
mkdir python-virtualenvs
cd python-virtualenvs
/work/chuck/$USER/.pythons/3.4/bin/pyvenv myenv3.4
# since python 3.5 the last line is changed to:
/work/chuck/$USER/.pythons/3.4/bin/python3 -m venv myenv_name
To work in the specific virtual environment issue command
source /work/chuck/$USER/python-virtualenvs/myenv3.4/bin/activate
(to leave type deactivate
)
To install specific packages use pip in active virtual environment e.g.:
pip install numpy
pip install scipy
pip install matplotlib
pip install pandas
To list installed packages type:
pip freeze