2023-01-14

[Ubuntu 20.04.LTS.x64] Install newest [Python 3.11.1]

HOW TO INSTALL NEWEST PYTHON  FROM SOURCECODE
#UBUNTU 20.04.LTS.x64
##########################
REF: https://docs.posit.co/resources/install-python-source/
Posit - Install Python From Source
##########################

sudo apt-get update
sudo apt-get install gdebi-core

sudo apt-get build-dep python
sudo apt-get install libffi-dev libgdbm-dev libsqlite3-dev libssl-dev \
zlib1g-dev




cd /opt/setup/
export PYTHON_VERSION=3.11.1
export PYTHON_MAJOR=3


curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
tar -xvzf Python-${PYTHON_VERSION}.tgz
cd Python-${PYTHON_VERSION}


./configure \
--prefix=/opt/python/${PYTHON_VERSION} \
--enable-shared \
--enable-optimizations \
--enable-ipv6 \
LDFLAGS=-Wl,-rpath=/opt/python/${PYTHON_VERSION}/lib,--disable-new-dtags

make
sudo make install



# Looking in links: /tmp/tmp1i8nsd3d
# Processing /tmp/tmp1i8nsd3d/setuptools-65.5.0-py3-none-any.whl
# Processing /tmp/tmp1i8nsd3d/pip-22.3.1-py3-none-any.whl
# Installing collected packages: setuptools, pip
# WARNING: The scripts pip3 and pip3.11 are installed in '/opt/python/3.11.1/bin' which is not on PATH.
# Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
# Successfully installed pip-22.3.1 setuptools-65.5.0
# WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
# root@3900xl /opt/setup/Python-3.11.1#






# Install pip into the version of Python that you just installed:
curl -O https://bootstrap.pypa.io/get-pip.py
sudo /opt/python/${PYTHON_VERSION}/bin/python${PYTHON_MAJOR} get-pip.py



# Verify that Python is installed by running the following command:
/opt/python/${PYTHON_VERSION}/bin/python${PYTHON_MAJOR} --version


# (Optional) Add Python to the system PATH:
# PATH=/opt/python/<PYTHON-VERSION>/bin/:$PATH
PATH=/opt/python/3.11.1/bin/:$PATH

# #GLOBAL PATH VARIABLES:
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/jdk/bin:/opt/script:/opt/lampp/bin:/usr/local/pgsql/bin:/opt/mariadb/bin:/opt/python/3.11.1/bin
# export PATH