I’m trying to start apache + mod_wsgi and I have strong restriction to put source .py files onto server, so I compile them first and put .pyo files onto server.
That’s what I have in apache conf:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonPath /var/wwwroot/
WSGIPythonOptimize 1
WSGIScriptAlias /home /var/wwwroot/home.pyo
But mod_wsgi raises the error (cut from apache error log):
Failed to parse WSGI script file '/var/wwwroot/home.pyo'.
Exception occurred processing WSGI script '/var/wwwroot/home.pyo'.
File "/var/wwwroot/home.pyo", line 1
m\xf2
^
SyntaxError: invalid syntax
I tried to google but couldn’t find an answer for does mod_wsgi work with pre-compiled python code.
This was answered on the mod_wsgi list at:
http://groups.google.com/group/modwsgi/browse_thread/thread/5da316e3480eab7f
The short answer is that only the WSGI script file needs to be source code and as others have pointed out, just have that have appropriate lines to set up sys.path if necessary and then import the actual WSGI application entry point from the .pyo version of module elsewhere.