1

How to correctly and safely move a python pyramid application? SEE BELOW, I updated the details after feedback in the comments.

I first used the following command to prepare the environment:

virtualenv --relocatable ENV

After that, the app was still working correctly. I then moved the python app to another directory, but get the following error:

[Thu Jul 27 16:09:08.884534 2017] [wsgi:error] [pid 14775] [remote 185.54.183.194:58084] mod_wsgi (pid=14775): Target WSGI script '/home/develop/web/checklist/prod/backend/pyramid.wsgi' cannot be loaded as Python module.
[Thu Jul 27 16:09:08.884660 2017] [wsgi:error] [pid 14775] [remote 185.54.183.194:58084] mod_wsgi (pid=14775): Exception occurred processing WSGI script '/home/develop/web/checklist/prod/backend/pyramid.wsgi'.

 .......

 [Thu Jul 27 16:09:08.886634 2017] [wsgi:error] [pid 14775] [remote
 185.54.183.194:58084] pkg_resources.DistributionNotFound: The 'checklist' distribution was not found and is required by the application

(checklist is the python application). I changed the path's in the apache config of WSGIDaemonProcess and WSGIScriptAlias to the new location. And I changed the path in the pyramid.ini file used in WSGIDaemonProcess. My apache config:

    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIDaemonProcess checklistTest user=apache group=apache threads=4 python-path=/home/develop/web/test/checklist/backend:/home/develop/web/test/checklist/backend/env/lib/python3.4/site-packages
    WSGIScriptAlias /bdh-checklist-test /home/develop/web/test/checklist/backend/pyramid.wsgi
    <Directory /home/develop/web/test/checklist/backend>
      WSGIProcessGroup checklistTest
      Require all granted
    </Directory>

I updated the above config after feedback from Graham. I compiled mod_wsgi with the same python version as used by the python app (version 3.4). However, I still can't use the python-home attribute, it results in a timeout error (with the relocatable environment):

Timeout when reading response headers from daemon process 'checklistTest':

In case I use the python-home, the above DaemonProcess entry looks like:

WSGIDaemonProcess checklistTest user=apache group=apache threads=4 python-home=/home/develop/web/test/checklist/backend/env/lib/python3.4

How to solve this? Why should I use the python-home instead of python-path? I have to include the path to the app itself in the python-app attribute, else the apache log will contain an error saying that it can't find the app distribution.

edbras
  • 4,145
  • 9
  • 41
  • 78
  • 1
    Not that it will solve your problem, but you should not use ``python-path`` to point at a ``site-packages`` of a virtual environment, use ``python-home`` to point to the root of the virtual environment instead. See http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html – Graham Dumpleton Jul 27 '17 at 21:22
  • Thanks, but that doesn't work, tried it (again), but it results in a gateway timeout, nothing useful in the log files. No idea why, maybe because, according to the doc's the python version should be the same as the version used to compile the mod_wsgi module, I donno.. – edbras Jul 28 '17 at 16:13
  • 1
    What version of Python is mod_wsgi compiled for. See following document, starting at http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-shared-library – Graham Dumpleton Jul 28 '17 at 21:03
  • But why should I want to use that? It makes it very fragile, as I want to use other Python versions for different apps in the near future. – edbras Jul 29 '17 at 09:08
  • 1
    What are you claiming is fragile? You cannot force mod_wsgi compiled for one Python version/installation, to use a difference Python version/installation. Mixing versions or installations will fail in bad ways. – Graham Dumpleton Jul 29 '17 at 10:14
  • Ok, didn't know that, why can't I mix versions? – edbras Jul 29 '17 at 16:56
  • Thanks, I was just reading about it. I noticed your name on my paces ;) – edbras Jul 29 '17 at 18:36
  • 1
    Because mod_wsgi is embeding the Python interpreter into another application (Apache) by compiling against and linking in the Python shared library. It is therefore bound to that specific program. It doesn't just execute the ``python`` executable for the version of Python you want to use. – Graham Dumpleton Jul 29 '17 at 20:59
  • I compiled mod_wsgi 4.5.17 with the same python version as the app (3.4) and it's working, but not when using the python-home attribute as you suggested in the first post. If I set python-home to "python-home=/home/develop/web/checklist/test/bla/backend/env/lib/python3.4", I get the following error in the apache log: "Timeout when reading response headers from daemon process 'checklistTest': /home/develop/web/checklist/test/bla/backend/pyramid.wsgi". I enabled apache debug, but couldn't discover more useful info. Any idea how to solve this? – edbras Jul 31 '17 at 12:54
  • Edit your question showing your current configuration. What was included was incomplete, missing for example ``WSGIProcessGroup``. – Graham Dumpleton Jul 31 '17 at 20:47
  • Good idea, I just updated the content with the current config. Let me know what you think please. Thanks. – edbras Aug 01 '17 at 16:13
  • Your configuration is still missing ``WSGIScriptAlias`` directive and what it is set to. – Graham Dumpleton Aug 01 '17 at 21:00
  • Oepss, sorry about that, I just added it (missed have accidentally deleted it) – edbras Aug 02 '17 at 07:25
  • The ``python-home`` option is only for the virtual environment location. Still use ``python-path`` for where application code is. – Graham Dumpleton Aug 03 '17 at 00:20
  • 1
    Anyway, the summary seems to be that you are suggesting that for a relocatable virtual environment, that using ``python-home`` doesn't work. Correct? You can still use ``python-path`` against ``site-packages`` in that case, just that use of ``python-home`` is preferred as usually results in errors mixing Python versions being detected earlier. I will need to look at relocatable virtual environments to see if issue with those. – Graham Dumpleton Aug 03 '17 at 00:22
  • Yes Graham, what you write is correct, I use an relocatable environment (just added it to the description). I have to say that the global installed python version is exactly the same as the on in the environment, maybe that is why not-using the python-home is not giving me any problems. – edbras Aug 03 '17 at 07:27

0 Answers0