# Topic covered
Python different version installation in 2 ways
* Using Source code
* Using apt-get
Pip installation
1. Python installation
Way 1 - Using Source code
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
# 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
./configure --enable-optimizations # optional
sudo make
sudo make install
Way 2 - Using Apt
- 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.7
sudo apt install python3.7
python3.7 --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