DevHeads.net

upgrading python

I am running CentOS 7 and I have python version:

Python 2.7.5 (default, Sep 15 2016, 22:37:39)

I need a newer version of 2.7 to pick up a bug fix. How can I do that
(without breaking anything in CentOS)?

Comments

Re: upgrading python

By Kai Grunau at 12/05/2017 - 09:16

On 05.12.2017 14:05, Larry Martell wrote:

Re: upgrading python

By Larry Martell at 12/05/2017 - 09:24

On Tue, Dec 5, 2017 at 8:16 AM, Kai Grunau < ... at geomar dot de> wrote:
I am not familiar with that. This is for a django app, using nginx,
uWSGI, and mysql - will it integrate easily with those components?

Re: upgrading python

By Kai Grunau at 12/05/2017 - 09:45

On 05.12.2017 14:24, Larry Martell wrote:
I think is easy to  work with those components

Re: upgrading python

By Marc Gouw at 12/05/2017 - 11:00

On 12/05/2017 02:45 PM, Kai Grunau wrote:
I've happily been using python virtual environments (similar to
anaconda) alongside with Apache, WSGI & django for a long time. The
setup using NGINX should be almost the same (with some small differences
in setting up NGINX, of course).

I would suggest "virtualenv" instead of anaconda: The principle is the
same, but it offers just a bit more flexibility and customization.
Virtualenv creates a local (non-system) installation of python, and you
can create different collections of packages stored as different
environments. In this way you can have multiple versions of python +
different collections of packages all living happily side by side on the
same machine.

Regarding the setup with uWSGI + NGINX, the Django documentation "How to
use Django with Apache and mod_wsgi"  is excellent:
<a href="https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/" title="https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/">https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/</a>

There is also a similar setup for NGINX on readthedocs (which I assume
will also work):
<a href="http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html" title="http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html">http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html</a>

For the rest: Google is your friend, you'll find lots of information on
each of these topics.

Good luck!

Marc

Re: upgrading python

By Larry Martell at 12/05/2017 - 11:15

On Tue, Dec 5, 2017 at 10:00 AM, Marc Gouw <marc. ... at embl dot de> wrote:
This is a very mature app that we have deployed in many sites. The
older sites run CentOS 6 and use apache and modwsgi. The newer sites
run CentOS 7 and use nginx and uWSGI. So we am very familiar with
their respective setups. But I have never used anything other then the
out of the box python that came with the OS. So I am not sure how to
get that nor if it will break anything. I am going to investigate Pete
Biggs' suggestion to use Software Collections.

Re: upgrading python

By Andrew Holway at 12/05/2017 - 11:19

+1 for SCL

Re: upgrading python

By Pete Biggs at 12/05/2017 - 09:22

On Tue, 2017-12-05 at 14:16 +0100, Kai Grunau wrote:
Or use Software Collections, the Python27 package from there has 2.7.13

<a href="https://www.softwarecollections.org/en/scls/rhscl/python27/" title="https://www.softwarecollections.org/en/scls/rhscl/python27/">https://www.softwarecollections.org/en/scls/rhscl/python27/</a>

<a href="https://wiki.centos.org/AdditionalResources/Repositories/SCL" title="https://wiki.centos.org/AdditionalResources/Repositories/SCL">https://wiki.centos.org/AdditionalResources/Repositories/SCL</a>

P.

Re: upgrading python

By Larry Martell at 12/11/2017 - 17:09

On Tue, Dec 5, 2017 at 8:22 AM, Pete Biggs < ... at biggs dot org.uk> wrote:
I followed the instructions at the first link and I still only seem to
have 2.7.5. How can I specify a newer version?

Re: upgrading python

By Clint Dilks at 12/11/2017 - 17:25

On Tue, Dec 12, 2017 at 10:09 AM, Larry Martell <larry. ... at gmail dot com>
wrote:

Hi, perhaps reading <a href="https://www.softwarecollections.org/en/" title="https://www.softwarecollections.org/en/">https://www.softwarecollections.org/en/</a> and
<a href="https://www.softwarecollections.org/en/scls/rhscl/python27/" title="https://www.softwarecollections.org/en/scls/rhscl/python27/">https://www.softwarecollections.org/en/scls/rhscl/python27/</a> will help.

Have you done scl enable python27 bash in your current shell?

Re: upgrading python

By Larry Martell at 12/11/2017 - 17:32

On Mon, Dec 11, 2017 at 4:25 PM, Clint Dilks < ... at scms dot waikato.ac.nz> wrote:
Thanks. Missed that. Now I do get 7.5.13 but it seems I have to type
that command in each new shell. Can I make that the default python? I
want django and uWSGI to use that version.

Re: upgrading python

By Larry Martell at 12/12/2017 - 09:27

On Mon, Dec 11, 2017 at 4:32 PM, Larry Martell <larry. ... at gmail dot com> wrote:
After I issue the command scl enable python27 bash, and my python is
then 2.7.13, when I run pip will it use 2.17.13 to build what I am
downloading?

Re: upgrading python

By m.roth at 12/12/2017 - 10:11

Larry Martell wrote:
mark

Re: upgrading python

By Larry Martell at 12/12/2017 - 10:17

On Tue, Dec 12, 2017 at 9:11 AM, <m.roth@5-cent.us> wrote:
Sorry, missed your previous post. Ended up that I had to reinstall
uWSGI using the 2.5.13 pip, and then link
/opt/rh/python27/root/usr/bin/uwsgi to /usr/bin/uwsgi. Now that I have
it running, hopefull it will resolve the issue I had (which was a bug
in the 2.7.5 zlib).

Re: upgrading python

By Pete Biggs at 12/11/2017 - 17:54

I believe doing something like

source scl_source enable python27

in .bashrc will do that. But the scl_source command is a fairly recent
addition so hopefully you have it. See:

<a href="https://access.redhat.com/solutions/527703" title="https://access.redhat.com/solutions/527703">https://access.redhat.com/solutions/527703</a>

Try it from a command line first before committing it to your .bashrc

There are some things on the web about using django and uWSGI with
software collections. For instance:

<a href="https://developers.redhat.com/blog/tag/django/" title="https://developers.redhat.com/blog/tag/django/">https://developers.redhat.com/blog/tag/django/</a>

but I know nothing about any of the applications so I don't know how
relevant this is.

P.

Re: upgrading python

By Johnny Hughes at 12/11/2017 - 17:47

On 12/11/2017 03:32 PM, Larry Martell wrote:
You likely can not make it the default python .. because all the system
based things will likely break.

However, you CAN add (call) the correct environment to your startup
scripts for the proper deamons in init, which should run the required
servers with the version of python that you want.

The whole purpose of SCLs is to allow multiple versions of the same
items to run together on a given machine, and you can pick the one you
need for a give application/server service .. WHILE, not breaking 9in
the case of python) things like yum :).

Re: upgrading python

By Kenneth Porter at 12/11/2017 - 17:45

On 12/11/2017 1:32 PM, Larry Martell wrote:
The "default" python is a dependency for many other system packages, so
changing it without understanding what effect it will have on other
parts of the system would be dangerous. The idea behind Software
Collections is that you only affect the packages that truly need the
newer version.

How are you launching django and uWSGI? I'd suggest putting the SC
command in their startup scripts to keep the new version confined to them.

Re: upgrading python

By Frank Cox at 12/11/2017 - 17:44

On Mon, 11 Dec 2017 16:32:06 -0500

~/.bashrc

Re: upgrading python

By Pete Biggs at 12/11/2017 - 18:00

On Mon, 2017-12-11 at 15:44 -0600, Frank Cox wrote:
'scl enable python27 bash' creates a *new* shell with the correct
environment. As each invocation of bash reads .bashrc, it will also
create another new shell which will then read .bashrc and create
another shell ....

Depending on the speed of your machine and disks and how much memory
you have, it will take a few seconds to a few minutes to grind your
machine to a halt.

P.

Re: upgrading python

By m.roth at 12/11/2017 - 18:31

Pete Biggs wrote:
The simplest way is to . <path/to/python2.7/enable, and you're good to go.

mark

Re: upgrading python

By Clint Dilks at 12/11/2017 - 18:43

I definitely wouldn't make it the default python, but I have made it the
default for a particular user as long as they are not root.

In the past I have got python27-mod_wsgi and httpd24-httpd working together
by doing things like httpd24-httpd by doing things like

cat /opt/rh/httpd24/root/etc/sysconfig/httpd

export PATH=/opt/rh/python27/root/usr/bin:$PATH
export
LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Re: upgrading python

By Larry Martell at 12/11/2017 - 18:50

On Mon, Dec 11, 2017 at 5:43 PM, Clint Dilks < ... at scms dot waikato.ac.nz> wrote:
I am running nginx and uWSGI. I added this to /etc/systemd/system/uwsgi.service:

ExecStart=/usr/bin/scl enable python27 bash; /usr/bin/uwsgi --emperor
/etc/uwsgi/sites

But it did not start:

Loaded: loaded (/etc/systemd/system/uwsgi.service; enabled; vendor
preset: disabled)
Active: failed (Result: start-limit) since Mon 2017-12-11 17:20:36
EST; 6s ago
Process: 24492 ExecStart=/usr/bin/scl enable python27 bash;
/usr/bin/uwsgi --emperor /etc/uwsgi/sites (code=exited,
status=1/FAILURE)

Re: upgrading python

By Kenneth Porter at 12/11/2017 - 18:57

On 12/11/2017 2:50 PM, Larry Martell wrote:
You probably want:

ExecStart=/usr/bin/scl enable python27 '/usr/bin/uwsgi --emperor /etc/uwsgi/sites'

See:

<a href="https://linux.die.net/man/1/scl" title="https://linux.die.net/man/1/scl">https://linux.die.net/man/1/scl</a>

Re: upgrading python

By Larry Martell at 12/11/2017 - 19:21

On Mon, Dec 11, 2017 at 5:57 PM, Kenneth Porter < ... at sewingwitch dot com> wrote:
With that change it starts, but still with 2.7.5:

*** Starting uWSGI 2.0.13.1 (64bit) on [Mon Dec 11 17:47:19 2017] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 28 July 2016 12:32:18
os: Linux-3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016
nodename: padev
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /etc/uwsgi/sites
detected binary path: /usr/bin/uwsgi
chdir() to /usr/local/motor/motor
your processes number limit is 195775
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /usr/local/motor/motor.sock fd 3
Python version: 2.7.5 (default, Sep 15 2016, 22:37:39) [GCC 4.8.5
20150623 (Red Hat 4.8.5-4)]
*** Python threads support is disabled. You can enable it with
--enable-threads ***
Python main interpreter initialized at 0x13a75e0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1115752 bytes (1089 KB) for 10 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x13a75e0
pid: 25616 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 25616)
spawned uWSGI worker 1 (pid: 25693, cores: 1)
spawned uWSGI worker 2 (pid: 25694, cores: 1)
spawned uWSGI worker 3 (pid: 25695, cores: 1)
spawned uWSGI worker 4 (pid: 25696, cores: 1)
spawned uWSGI worker 5 (pid: 25697, cores: 1)
spawned uWSGI worker 6 (pid: 25699, cores: 1)
spawned uWSGI worker 7 (pid: 25700, cores: 1)
spawned uWSGI worker 8 (pid: 25701, cores: 1)
spawned uWSGI worker 9 (pid: 25702, cores: 1)
spawned uWSGI worker 10 (pid: 25703, cores: 1)