profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Friday, November 2, 2018

Install and Default python 3.x on CentOS 7


TLDR
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#install the centos7 repository
sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm
#install python3.6
sudo yum -y install python36u
# install pip3 for python 3.x (since pip is for python 2.x)
sudo yum -y install python36u-pip
# it shows the default python 2.x
python -V
# this is how you run the python 3.x but it is inconvenient
python3.6 -V
# so set alias
# when we run python the OS will not autotranslate that the alias value python3.6
alias python=python3.6
alias pip=pip3.6
# make these alias changes permanent
source ~/.bashrc
# install virtualenv
pip install virtualenv
# how to create a virtual environment for python3? 
# virtualenv <name of the virtual environment>

When we get our linux box it has python 2.7.x but we know that most of the development and the future sustenance is towards python 3.x. So let us do these

  1. Install CentOS IUS repository
  2. Install python 3.x
  3. Install pip3.x
  4. Make python 3 as your default python
  5. Make pip3 as your default pip

Run line 2 to install the centos repository.
Run line 4 to install python 3.6
Run line 6 to install the python package manager 3.x for python 3.x
Run line 13-17 for all user accounts where you want the python 3.x and pip3.x to be the default.
Log in as that user and run 13-17.
Bonus : - Run line 18 to have the virtual environment installed for your system.
Now run python and it defaults to python 3.6. do exit() to exit out of python.
Run pip and it will default to pip3.6.