Ask Your Question

Extending module search path (PYTHONPATH) for WSGI daemon enabled Apache running OpenStack Horizon (Kilo)

asked 2015-07-16 08:47:27 -0500

holger-king gravatar image

updated 2015-07-22 10:20:54 -0500

Dear Community,

we are currently running:

  • Kilo-OpenStack distribution RDO deployed via PACKSTACK
  • Apache 2.4
  • Python 2.7
  • Django 1.8.1
  • on RHEL 7.1

And we want to allow a remote debugging session using Python "pydevd" in the Django web application Horizon. That's why it is necessary to include "import pydevd" into the Python source.

The problem now: although Horizon is running in WSGI daemon mode in an Apache 2.4 environment on RHEL 7.1, we want to enhance the existing PYTHONPATH that is responsible for defining the Python module search path. This is necessary to successfully call the above import directive for pydevd. Therefore, we enhanced all "WSGIDaemonProcess" directives found in Apache configuration files below "/etc/httpd/conf.d" using the "python-path" parameter:

WSGIDaemonProcess keystone_main display-name=keystone-main group=keystone processes=1 threads=2 user=keystone python-path=/tmp/pysrc

Details for the usage of this directive can be found (here)! A helpful web page can also be found (here)!

But: as soon as we restart Apache, the following error occurs:

rb-openstack-d python[2187]: import pydevd
rb-openstack-d python[2187]: ImportError: No module named pydevd

That means: the PYTHONPATH enhancement seems not to work. So, what to do??

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-07-22 10:19:32 -0500

holger-king gravatar image

updated 2015-07-22 11:08:52 -0500

We found the root cause: the OpenStack deployment tool "packstack" creates an individual Apache/httpd "SystemD" unit file below "/lib/systemd/system/httpd.service.d" called "openstack-dashboard.conf". This file contains:

ExecStartPre=/usr/bin/python /usr/share/openstack-dashboard/ collectstatic --noinput
ExecStartPre=/usr/bin/python /usr/share/openstack-dashboard/ compress --force


As for this Python process no custom environment variable PYTHONPATH is set pointing to "/tmp/pysrc", the above exceptions occurred. Now, we manipulated this SystemD unit file to take care of our custom environment variable PYTHONPATH pointing to "/tmp/pysrc" in that way:

ExecStartPre=PYTHONPATH=/tmp/pysrc /usr/bin/python /usr/share/openstack-dashboard/ collectstatic --noinput
ExecStartPre=PYTHONPATH=/tmp/pysrc /usr/bin/python /usr/share/openstack-dashboard/ compress --force

IMPORTANT: do not forget to execute "systemctl daemon-reload" when unit files have changed!

With that change we also can confirm that the "python-path" parameter of the "WSGIDaemonProcess" used in the Apache2 virtual hosts is properly working! BUT: when accessing the OpenStack horizon dashboard via the browser the first time after this change, the Apache2 "horizon_error.log" throws again a missing "ImportError: No module named pydevd".

The final solution brought the move of "pydevd" from "/tmp/pysrc" to "/usr/lib/python2.7/site-packages/pydevd" in combination with the "python-path" adaption in the Apache2 virtual host configuration :-)

And voilà - now, it's working successfully :-) Based on this finding we can mark this question as answered :-) Finally, we want to thank you for your contributions and important recommendations!

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-07-16 08:47:27 -0500

Seen: 1,271 times

Last updated: Jul 22 '15