Centos Python Installation Guide with no Pain

Centos 7 + Python 3(4,5,6,7,8) installation guide with no pain. As for me.

I can’t even say how many times I have to update my python executables for web servers and how much pain I feel during this routine.

Usual Google\StackOverflow advice only describes one particular problem. But there’re few of them, and they’re different so you spent hours trying to collect them all and pick the right decision.

Then you just drop it and use yum for any latest python version available!

Here I’ll show you and make a reminder for myself about how to install modern python in the best way, once, without pain.

I use Centos 7 typical install as for WebServer (minimal install could require to install tonnes of dev-libs and yum, be sure you prepared them before)

1. Preparations:

You need to install some compil libs.

yum install gcc openssl-devel bzip2-devel libffi-devel

2. Download Python:

cd /usr/src
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar xzf Python-3.8.0.tgz
cd Python-3.8.0

3. Configure and install:

/configure --prefix=/usr/local --enable-optimizations --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make altinstall

Explanation: proof

  • –prefix – a usual place of an interpreter to install.
  • –enable-optimizations – python runs faster (proof)
  • –enable-shared allow use shared libs (proof)
  • LDFLAGS=”-Wl,-rpath /usr/local/lib” – most important – install system variable to locate .so modules for new python.
  • make altinstall – install without interruption of the system python

Errors you may see when LD path do not set or used incorrectly:

/var/www/web/venv/bin/python3.8: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory

Extra steps to fix it:

  • Check reference cat /etc/ld.so.conf – should load “* so.conf.d”
  • vi /etc/ld.so.conf.d/libpython3.8.conf
    • Add: /usr/local/lib/
    • Add: /usr/local/lib/libpython3.8.so.1.0
  • /sbin/ldconfig -v – to load them all (-v for visible mode)

You could also try this:

export LD_LIBRARY_PATH=/usr/local/lib 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/libpython3.8.so.1.0

How about pip and python3 from cmd:

Just adding symlinks to easy use of python3 and pip3:
(do not overlap with python2.7)

ln -s /usr/local/bin/python3.8 /usr/bin/python3
ln -s /usr/local/bin/pip3.8 /usr/bin/pip3


# python3
Python 3.8.0 (default, Oct 28 2019, 14:23:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
   pip3  [options]
# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.8 /usr/local/bin/python3.8-config /usr/local/lib/python3.8 /usr/include/python2.7 /usr/share/man/man1/python.1.gz /usr/src/Python-3.8.0/python
# which python

That’s all folks!

Next: How to mod_wsgi + Django + Celery and so on.

About trianglesis

Александр Брюндтзвельт - гений, филантроп, 100 гривен в кармане. Этот блог - "сток" моих мыслей и заметок. Достаточно одного взгляда на него, чтобы понять, что такой же бардак творится у меня в голове. Если вам этот бардак интересен - милости прошу.
Bookmark the permalink.

Comments are closed.