DEV Community

Mohamed M El-Kalioby
Mohamed M El-Kalioby Subscriber

Posted on • Updated on

Install Python 3.7+ on CentOS 7

This was my first time to install a recent version of Python on a CentOS. I always use Ubuntu and It is pretty easy using deadlysnakes PPA. so the only way was to compile the source code from python.org website.

The how-to is on the internet but I'm writing this as I did compilation serveral times as some options weren't set properaly. so let's go

  1. Install build tools sudo yum install gcc openssl-devel bzip2-devel libffi-devel
  2. Download the source from https://www.python.org/downloads/source/
  3. Extract the source
  4. run ./configure --enable-optimizations --enable-shared
  5. run make altinstall

Notes:

  • libffi is crucial, so don't forget it.
  • --enable-shared is required if you will compile any library with C Extension.
  • pip will be installed by default.
  • If you get /usr/local/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory, then do the following
  • export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib or
  • sudo ldconfig /usr/local/lib

Top comments (7)

Collapse
 
michaelcurrin profile image
Michael Currin • Edited

This one I found is similar but uses sudo make altinstall

computingforgeeks.com/how-to-insta...

And unzipping on the command line

tar xvf Python-3.8.3.tgz
Enter fullscreen mode Exit fullscreen mode
Collapse
 
michaelcurrin profile image
Michael Currin • Edited

I started using pyenv to install user-level python versions.

I don't know what repository it points to but you might get something more recent with that then yum. And then you can use pyenv to install new versions of python when they come out
github.com/pyenv/pyenv

Maybe there is an easier way to install but I came across this
gist.github.com/ysaotome/7956676

Collapse
 
michaelcurrin profile image
Michael Currin

Some more context for other readers. Python is available in the standard repos for Ubuntu and presumably CentOS for us with apt and yum. They are focused on stability so will be behind the latest.

but if you want the most recent you have to add another repository like the deadsnakes one for ubuntu.

Or download the source and compile Python yourself (I did this once and it took a long time and gave a lot of errors so would not recommend).

Is there no deadsnakes alternative for CentOS?

Collapse
 
mkalioby profile image
Mohamed M El-Kalioby

I tried but didn't find any.

Collapse
 
michaelcurrin profile image
Michael Currin

I found ius.io as a community list of packages but it only goes up to 3.6 :/

repo.ius.io/7/src/packages/p/

Collapse
 
michaelcurrin profile image
Michael Currin

Several not serveral

Collapse
 
mkalioby profile image
Mohamed M El-Kalioby

Thanks