Python35 on CentOS 7

Install packages

yum install -y centos-release-scl
yum install -y rh-python35-python

Enable rh-python35 globally for all users

cat > /etc/profile.d/rh_python35.sh <<_EOF
#!/bin/sh

source /opt/rh/rh-python35/enable
_EOF

Activate without relogin

. /etc/profile.d/rh_python35.sh

List available scl packages

scl --list

Activate rh-python35 in current bash session:

scl enable rh-python35 bash

Or in bash scripts:

export PATH=/opt/rh/rh-python35/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/rh-python35/root/usr/share/man:$MANPATH
export PKG_CONFIG_PATH=/opt/rh/rh-python35/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export XDG_DATA_DIRS="/opt/rh/rh-python35/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"

python --verion

Or this method:

. /opt/rh/rh-python35/enable

Create virtualenv in Python35:

Python 3 has a built-in support for virtual environments

  • https://docs.python.org/3/library/venv.html#module-venv
  • https://docs.python.org/3.6/whatsnew/3.6.html#id7
python3 -m venv venv

Use rh-python35 in supervisor

[program:app]
directory = /srv/app

environment = PATH=/srv/app/venv/bin:/opt/rh/rh-python35/root/usr/bin,
    LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64

command = /srv/app/venv/bin/gunicorn ...

stdout_logfile = /srv/app/logs/%(program_name)s.log
stdout_logfile_maxbytes = 5MB  ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups = 5     ; # of stdout logfile backups (default 10)
redirect_stderr = true

user = nobody
numprocs = 1
autostart = true
autorestart = true
startsecs = 5
stopwaitsecs = 60

Use rh-python35 in systemd

[Unit]
Description=Foo bar service
Requires=nginx.service
Before=nginx.service
After=network.target

[Service]
Type=notify
User=jenkins
Group=jenkins

Environment=LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64
Environment=PATH=/srv/app/venv/bin:/opt/rh/rh-python35/root/usr/bin

WorkingDirectory=/srv/app
ExecStart=/srv/app/venv/bin/uwsgi \
    --module app.wsgi \
    --http :8006 \
    ...

PIDFile=/srv/app/var/run/app.pid

KillMode=process
Restart=always
KillSignal=SIGTERM
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Ссылки по теме:

  1. How to enable Software Collections (SCL) on CentOS

Comments

comments powered by Disqus