# Topic covered
Python different version installation in 2 ways
* By - Building Python from Source
* Using deadsnakes PPA (For Latest Python Versions)
Pip installation
1. Python installation
Way 1 - Building Python from Source
Update the packages list and install the packages necessary to build Python source
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev libgdbm-dev libnss3-dev libedit-dev libc6-dev
# Download source code using wget command
# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz
# Extract
tar -xf Python-3.6.10.tgz
# Install
sudo cp -r Python-3.6.10 /opt
cd /opt/Python-3.6.10
sudo ./configure
sudo ./configure --enable-optimizations # optional
sudo make
sudo make install
Way 2 - Using deadsnakes PPA (For Latest Python Versions)
- https://linuxize.com/post/how-to-install-python-3-7-on-ubuntu-18-04/
- https://www.tecmint.com/install-python-in-ubuntu/
Start by updating the packages list and installing the prerequisites
sudo apt update
sudo apt install software-properties-common
Next, add the deadsnakes PPA to your sources list
sudo add-apt-repository ppa:deadsnakes/ppa
Once the repository is enabled, install Python 3.6
sudo apt install python3.6
python3.6 --version
Issue that may occur
sudo apt-get install build-essential
fatal error: Python.h: No such file or directory
sudo apt-get install python3-dev
sudo apt install libpython3.7-dev
2. Pip installation
# Install pip3
sudo apt install python3-pip
# Change default
alias pip=pip3
# pip for Python3.7
python3.7 -m pip install pip
# See Version
pip --version