Install Python on Linux
Install Python and Pip on Linux
- Check you’re python version with the following:
1
python3 --version
- If your python version is not the latest, do the following:
1
sudo apt install python3.x -y
- Note: if you are installing on an EC2 amazon linux, then use the following.
1
sudo amazon-linux-extras install python3.x
- Note: if you are installing on an EC2 amazon linux, then use the following.
- Then check the location of the installed package:
1
which python3.x
- Then update python3 parameter to your newly installed version of python.
1 2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.x 1 python3 --version
- Test that your new python version is working.
1
python3 -c 'import sys; print(sys.executable);'
See this post for details: https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu
- Update pip.
1
pip3 install --upgrade pip
- Note: if you don’t have pip3 install it:
1
sudo apt install python3-pip
- Note: if you don’t have pip3 install it:
- Check pip version and list packages.
1 2
pip3 --version pip3 list
Alternative Install via Python.org
- Download and install python directly from python.org:
1 2 3
cd /usr/src sudo wget https://www.python.org/ftp/python/3.x.x/Python-3.x.x.tgz sudo tar xzvf Python-3.x.x.tgz
Note: if unzipping local file then use:
1
tar xvf Python-3.x.x.tar.xz
Then, execute configure and install:
1 2 3 4
cd Python-3.x.x/ ./configure --with-openssl=/usr/src/openssl-1.0.2o --enable-optimizations sudo make -j 4 sudo make altinstall
- Update python3 parameter to your newly installed version of python.
1 2 3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.x 1 python3 -c 'import sys; print(sys.executable);' python3 --version
This post is licensed under CC BY 4.0 by the author.