Can I run python 3.11 django application on centOS 7? Failing to execute wsgi script

86 Views Asked by At

I am trying to run my django application based on python version 3.11.5 on centOS 7 with openssl version 3.0.11. My application is not able to find math module which comes in-built with python installation. But I am able to import math module in the python script. I am getting the below error, when I try to run my application on server:

[Tue Oct 24 20:44:17.092551 2023] [wsgi:error] [pid 30479] [client 129.214.105.163:35318] mod_wsgi (pid=30479): Failed to exec Python script file '/var/www/html/hmi.hmt/HMT/HMT/wsgi.py'.
[Tue Oct 24 20:44:17.092643 2023] [wsgi:error] [pid 30479] [client 129.214.105.163:35318] mod_wsgi (pid=30479): Exception occurred processing WSGI script '/var/www/html/hmi.hmt/HMT/HMT/wsgi.py'.
[Tue Oct 24 20:44:17.116764 2023] [wsgi:error] [pid 30479] Traceback (most recent call last):
[Tue Oct 24 20:44:17.116826 2023] [wsgi:error] [pid 30479]   File "/var/www/html/hmi.hmt/HMT/HMT/wsgi.py", line 17, in <module>
[Tue Oct 24 20:44:17.116976 2023] [wsgi:error] [pid 30479]     from django.core.wsgi import get_wsgi_application
[Tue Oct 24 20:44:17.117017 2023] [wsgi:error] [pid 30479]   File "/var/www/html/new_env/lib/python3.11/site-packages/django/__init__.py", line 1, in <module>
[Tue Oct 24 20:44:17.117097 2023] [wsgi:error] [pid 30479]     from django.utils.version import get_version
[Tue Oct 24 20:44:17.117130 2023] [wsgi:error] [pid 30479]   File "/var/www/html/new_env/lib/python3.11/site-packages/django/utils/version.py", line 1, in <module>
[Tue Oct 24 20:44:17.117200 2023] [wsgi:error] [pid 30479]     import datetime
[Tue Oct 24 20:44:17.117225 2023] [wsgi:error] [pid 30479]   File "/var/www/html/Python-3.11.6/Lib/datetime.py", line 12, in <module>
[Tue Oct 24 20:44:17.117299 2023] [wsgi:error] [pid 30479]     import math as _math
[Tue Oct 24 20:44:17.117337 2023] [wsgi:error] [pid 30479] ModuleNotFoundError: No module named 'math'

Math module is present in the python installation path(/var/www/html/Python-3.11.6/build/lib.linux-x86_64-3.11/math.cpython-311-x86_64-linux-gnu.so) Solutions I tried:

  • Reinstalled python
  • added math module path to PYTHONPATH (/var/www/html/Python-3.11.6/build/lib.linux-x86_64-3.11)

I read a discussion in centos community stating that CentOS 7 supports up to Python 3.6. The latest version available in the CentOS 7 repos is Python 3.6.8. And Python 3.11 development tools are not available in yum. CentOS 7 is officially supported until June 2024.You can build a later python from source but that's not a practical requirement for users.

So now I am doubting that this might be the reason for my failure. I believe that my python environment, environment variables, wsgi script and configuration files are properly set because I did multiple reinstallations with proper analysis.

This is my first time working on centos environment and so please let me know whether I am doing it wrong somewhere or is it compatability issue with centos 7.

0

There are 0 best solutions below