Saturday, January 6, 2018

How to install python 3.5 in CentOS 7 from source

At the time of writing, repository of Centos 7 contains python 3 of version 3.4, which is not the newest. And sometimes it's useful to have newer version. For example, I needed python 3.5. And here I will show you how to install it. We will be installing it from source.

1. Update repositories and install couple packages:
sudo yum update
sudo yum install zlib-devel openssl-devel


2. Download python 3.5 sources using curl (or wget):
curl -O https://www.python.org/ftp/python/3.5.4/Python-3.5.4.tgz

3. Extract files and change directory:
tar xzf Python-3.5.4.tgz
cd Python-3.5.4

4. Configure. Here I specified prefix /usr/local, this is necessary so that our custom python won't interfere with system's python. There are lots of other flags which you can specify, but this is a bare minimum:
./configure --prefix=/usr/local

5. Make and install system wide:
make
sudo make altinstall

Now you can check location of python3.5 by typing command:
which python3.5
and you should see this result:
/usr/local/bin/python3.5
Then run just python3.5 and start using it:
$ python3.5
Python 3.5.4 (default, Dec  5 2017, 09:20:08) 
As you see there is nothing difficult in installing custom python version from sources. I hope that was helpful to you.

No comments:

Post a Comment