I am trying to build an application in python which can be run from XAMPP's Apache, therefore I installed flask ($ pip install flask
) and I followed the following instructions for mod_wsgi installation http://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html.
I am using Apache from XAMPP, version 2.4.29, and python 3.6.4 from anaconda. I built the mod_wsgi file (version 4.6.4) by downloading from https://github.com/GrahamDumpleton/mod_wsgi/releases and using the following command :
$ ./configure --with-apxs=/Applications/XAMPP/xamppfiles/bin/apxs --with-python=/Users/pauline/anaconda3/bin/python3.6 --disable-framework
followed by make
and sudo make install
. I also tried it with and without --disable-framework
. After the installation, I checked otool -L mod_wsgi.so
which gives me (looks correct):
SCARLET10siMac4:modules pauline$ otool -L mod_wsgi.so
mod_wsgi.so:
@rpath/libpython3.6m.dylib (compatibility version 3.6.0, current version 3.6.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1452.23.0)
Also, when the Apache loaded modules is checked (by running this command: /Applications/XAMPP/xamppfiles/bin/httpd -M
), it shows wsgi_module (shared)
as well. And the output of sys.prefix
is /Users/pauline/anaconda3 and of sys.version
is 3.6.4
My application (image_download.py) has the simple following code :
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello')
def hello():
return 'Hello, World'
if __name__ == "__main__":
app.run()
And my wsgi file (image_download.wsgi) the following :
import sys
sys.path.insert(0,"/Users/pauline/Documents/Code/platform_projects/image_download/image_download")
from image_download import app as application
Finally, my http.conf virtual host part is :
WSGIPythonHome /Users/pauline/anaconda3
<VirtualHost *:80>
DocumentRoot "/Users/pauline/Documents/Code/platform_projects/image_download"
ServerName imageDownload.localhost
ServerAlias imageDownload.localhost
WSGIDaemonProcess image_download user=daemon group=daemon threads=5 home=/Users/pauline/Documents/Code/platform_projects/image_download python-path=/Users/pauline/Documents/Code/platform_projects/image_download:/Users/pauline/anaconda3/lib/python3.6/site-packages
WSGIScriptAlias / /Users/pauline/Documents/Code/platform_projects/image_download/image_download.wsgi
<Directory /Users/pauline/Documents/Code/platform_projects/image_download>
WSGIProcessGroup image_download
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
When I run my application as a localhost, it gives me an Server error! Error 500 and when I check the apache error log, it says the following:
[wsgi:error] [pid 6011] [remote ::1:50865] mod_wsgi (pid=6011): Target WSGI script '/Users/pauline/Documents/Code/platform_projects/image_download/image_download.wsgi' cannot be loaded as Python module.
[wsgi:error] [pid 6011] [remote ::1:50865] mod_wsgi (pid=6011): Exception occurred processing WSGI script '/Users/pauline/Documents/Code/platform_projects/image_download/image_download.wsgi'.
[wsgi:error] [pid 6011] [remote ::1:50865] Traceback (most recent call last):
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/werkzeug/http.py", line 27, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from urllib.request import parse_http_list as _parse_list_header
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/urllib/request.py", line 2585, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from _scproxy import _get_proxy_settings, _get_proxies
[wsgi:error] [pid 6011] [remote ::1:50865] ImportError: dlopen(/Users/pauline/anaconda3/lib/python3.6/lib-dynload/_scproxy.cpython-36m-darwin.so, 2): Symbol not found: __cg_jpeg_resync_to_restart
[wsgi:error] [pid 6011] [remote ::1:50865] Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
[wsgi:error] [pid 6011] [remote ::1:50865] Expected in: /Applications/XAMPP/xamppfiles/lib/libjpeg.8.dylib
[wsgi:error] [pid 6011] [remote ::1:50865] in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
[wsgi:error] [pid 6011] [remote ::1:50865]
[wsgi:error] [pid 6011] [remote ::1:50865] During handling of the above exception, another exception occurred:
[wsgi:error] [pid 6011] [remote ::1:50865]
[wsgi:error] [pid 6011] [remote ::1:50865] Traceback (most recent call last):
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/Documents/Code/platform_projects/image_download/image_download.wsgi", line 13, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from image_download import app as application
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/Documents/Code/platform_projects/image_download/image_download.py", line 9, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from flask import Flask
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/flask/__init__.py", line 17, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from werkzeug.exceptions import abort
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/werkzeug/__init__.py", line 151, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] __import__('werkzeug.exceptions')
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/werkzeug/exceptions.py", line 71, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from werkzeug.wrappers import Response
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/werkzeug/wrappers.py", line 27, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from werkzeug.http import HTTP_STATUS_CODES, \\
[wsgi:error] [pid 6011] [remote ::1:50865] File "/Users/pauline/anaconda3/lib/python3.6/site-packages/werkzeug/http.py", line 30, in <module>
[wsgi:error] [pid 6011] [remote ::1:50865] from urllib2 import parse_http_list as _parse_list_header, \\
[wsgi:error] [pid 6011] [remote ::1:50865] ModuleNotFoundError: No module named 'urllib2'
When I run the program via Flask, it runs completely fine. However, when running it via apache localhost, it shows server error. Therefore, I mostly suspect that the problem is coming from wrong installation of mod_wsgi.so
, however, I cannot be able to debug it, although installation steps (mentioned above) were seem to be correct.
pip install
method as described in pypi.org/project/mod_wsgi Once installed, usemod_wsgi-express module-config
to generate the config you should add to Apache to load the mod_wsgi module. It should generate aLoadFile
directive to ensure Anaconda Python library loaded correctly. – Graham Dumpletonpip install
method and got exactly the same errors. Indeed the PHP modules are loaded from Apache as well, what could I do instead ? – Paulinels -las /Applications/XAMPP/xamppfiles/lib
? – Graham DumpletonXAMPP
distribution? It is the cause of the problems here are isn't going to work with Anaconda Python or even System Python when using mod_wsgi. Their shipping of their own libraries for everything is going to cause conflicts. – Graham Dumpleton