In this chapter we have discussed the steps to install Python on a Linux machine.
Prerequisites for Python installation
Before beginning Python installation on your system, follow the below steps:
- # Start by making sure your system is up to date
yum update
- # Compilers and related tools
yum groupinstall -y “development tools”
- # Libraries needed during compilation to enable all features of Python
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
- # If you have a clean “minimal” installation of CentOS, you also need the wget tool:
yum install -y wget
yum install libffi-devel
Installing Python
Below are the commands to install Python on your system:
- #Check if python is already installed on the machine
python –version
- #If python version is greater than or equal to 3.5, skip to “Installing Intellicuspy” section
#If Python version is 2.7 or more, move further
#Navigate to a directory where Python should be installed, to be referred as SOURCEDIR henceforth
cd SOURCEDIR
- #If pip is not installed then install pip using command
# yum install epel-release
# yum install python-pip
#Install virtual environment on Python 2.7
pip2.7 install virtualenv
#This will create a directory named source
virtualenv source
- #Navigate to the directory created above
cd source
- #Download Python 3.7 setup
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
- #Extract the above downloaded setup
tar xf Python-3.7.3.tar.xz
- #Navigate to the extracted directory
cd Python-3.7.3
- #Setup environment
./configure –enable-optimizations
make altinstall
- #Download PIP
wget https://bootstrap.pypa.io/get-pip.py
- #Install PIP
python3.7 get-pip.py
- #Check if python is installed on the machine correctly
python3.7 –version
Go to SOURCEDIR
Creating Python Environment
Follow the below steps to create Python environment on your system:
- 7 -m venv intellicuspython
#The above command should generate a directory named intellicuspython, note the location of this directory and we will call it PYTHONDIR henceforth.
- source intellicuspython/bin/activate
#Activates Python environment
- python –version
#This should display the version of python as Python 3.7.3
- #Deactivates Python environment
deactivate