0

I've written a flask app using poetry and want to run it under the control of apache and wsgi. I've spent hours scouring documentation and experimenting and I've learned a lot but still have not figured it out. Here is the blow by blow:

The app works when I run it directly from the command line in poetry:

 python3 ./otproject/otpflask/src/run.py
 * Serving Flask app 'teacher' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 141-706-196
^Crpsalas@otproject:~/mydev/development$

According to poetry, my venv is here:

$ poetry env info

VirtualEnv
Python:         3.8.10
Implementation: CPython
Path:           /home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8
Valid:          True

System
Platform: linux
OS:       posix
Python:   /usr

Then I configure my apache mod_wsgi as follows

<VirtualHost *:80>
    WSGIDaemonProcess test python-home=/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8
    WSGIProcessGroup test
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias /test /var/www/test/test.wsgi
    <Directory /var/www/test/src/>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

The wsgi python script test.wsgi looks like this:

#!/usr/bin/env python
from otproject.otpflask.teacher import app as application

But when I restart the apache service it fails horribly:

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f99756e4c40 (most recent call first):
<no Python frame>
[Sun Jul 25 20:35:24.503068 2021] [wsgi:warn] [pid 154900:tid 140297076886592] (13)Permission denied: mod_wsgi (pid=154900): Unable to stat Python home /home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
  PYTHONHOME = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python3'
  sys.base_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
  sys.base_exec_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
  sys.exec_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
  sys.path = [
    '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python38.zip',
    '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python3.8',
    '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python3.8/lib-dynload',
  ]
Sean W
  • 5,663
  • 18
  • 31
pitosalas
  • 10,286
  • 12
  • 72
  • 120

0 Answers0