oeplatform icon indicating copy to clipboard operation
oeplatform copied to clipboard

Python version differ

Open jh-RLI opened this issue 2 years ago • 8 comments

We still have some inconsistencies regarding the Python version in our technology stack. We should create a process or workflow to track and set the python version (or version range).

Maybe also add a logging message if available python version is not supported. The production server is running Python 3.6

For example: the ci and the readme statements are on newer versions (Py 3.8 and 3.9) than the production server.

jh-RLI avatar Dec 12 '22 22:12 jh-RLI

We will attempt to update the Python version on the server. This requires us to also recompile the mod_wsgi / wsgi installation on the server otherwise django will not run anymore.

I assume that we need to copy some tarballs to the server in order to install Python and mod_wsgi.

Update Python: We can simply install a new python verison i recomend something like python3.9 / 3.10

The more difficult part is updating the wsgi installation. We need to make sure that:

  • the virtual env is using the new python
  • WSGI should be setup in deamon mode
  • ??? remove current wsgi installation ???
  • Reinstall wsgi (mod_wsgi) https://modwsgi.readthedocs.io/en/master/user-guides/quick-installation-guide.html
  • more .... https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/modwsgi/ https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html#virtual-environment-and-python-version

@wingechr Can you review these basic steps? never installed wsgi before, also don't have much experience with appache server configuration. not the best condition to do this task, but we will try on TOEP first.

jh-RLI avatar Dec 13 '23 11:12 jh-RLI

I dont think that will work.

The problem is not the python package but the (compiled) library for apache. Assuming this is a debian/ubuntu system, this is installed with apt install libapache2-mod-wsgi-py3, This is precompiled against a specific version of python and will not properly work with other ones. You also cannot choose which version, it the depends on your debian version.

as root, go to cd /usr/lib/apache2/modules and list the compiled libraries: ls -l | grep mod_wsgi

On my system, this looks like this:

lrwxrwxrwx 1 root root   15 2022-09-12T23:03:02 mod_wsgi.so -> mod_wsgi.so-3.7
-rw-r--r-- 1 root root 240K 2022-09-12T23:03:02 mod_wsgi.so-3.7

apache uses the mod_wsgi.so which is a symlink to mod_wsgi.so-3.7, so I am stuck with python3.7, i.e. i have to use 3.7 for my virtualenvs if I want to use it behind the apache server

wingechr avatar Dec 13 '23 12:12 wingechr

In principle, it should be possible to place other versions of mod_wsgi.so in this folder and change the symlink. maybe

wingechr avatar Dec 13 '23 12:12 wingechr

So you can try this:

  • install a new (additional) version of python (! you should not replace the default python3 in your debian, it might break the system) (This here worked for me: https://tiltingatwindmills.dev/how-to-install-an-alternate-python-version/)
  • install the mod_wsgi package in this python site-packages
  • link the apache there ,e.g. mod_wsgi.so -> /usr/local/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-36m-x86_64-linux-gnu.so
  • hope :-)

wingechr avatar Dec 13 '23 12:12 wingechr

(also you need to have root privileges to change the apache symlink)

wingechr avatar Dec 13 '23 12:12 wingechr

(or, apparently you can instead just change the path to the so-file here: /etc/apache2/mods-available/wsgi.load)

wingechr avatar Dec 13 '23 12:12 wingechr

The problem is not the python package but the (compiled) library for apache.

True. Wasnt aware that im referencing the python package.

So you can try this:

  • install a new (additional) version of python (! you should not replace the default python3 in your debian, it might break the system) (This here worked for me: https://tiltingatwindmills.dev/how-to-install-an-alternate-python-version/)
  • install the mod_wsgi package in this python site-packages
  • link the apache there ,e.g. mod_wsgi.so -> /usr/local/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-36m-x86_64-linux-gnu.so
  • hope :-)

This soundls like what i was hoping for :) HOPE it will work :) This means we only install mod_wsgi in the python env. This will then ensure the wsgi is build with the python used to create the env? In this case i hope for a simple (env) pip install mod_wsgi. This would be great and sounds to simple already :P

jh-RLI avatar Dec 13 '23 13:12 jh-RLI

It might just work, but that also means that all other python wsgi applications behind the apache(i assume there are no others) must also use the same python version.

wingechr avatar Dec 13 '23 14:12 wingechr