Skip to content Skip to sidebar Skip to footer

WSGI: ImportError: No Module Named Hello (module In The Same Directory Of The Main .py File)

This is not a duplicate of Apache with virtualenv and mod_wsgi : ImportError : No module named 'django' since here I'm not using any virtualenv, and also I'm not trying to import a

Solution 1:

Apache does not change to the current working directory, thus it will not search for hello where you think.

You might change app.py in following way.

import os, time, sys
from bottle import route, run, template, default_ap
# add the scripts directory to the python path so that hello can be found
sys.path.insert(0, os.path.realpath(os.path.dirname(__file__)))

Advantage you do not have to mess with the apache config files


Solution 2:

The solution is:

  • to have a WSGIDaemonProcess ... python-path=... indeed,

  • but also a WSGIScriptAlias ... process-group=... (not sure why this process-group parameter is linked to allowing or not to load modules from the same directory, but it works!)

Example:

WSGIScriptAlias / /var/www/test/app.py process-group=test
WSGIDaemonProcess test user=www-data group=www-data processes=5 threads=5 display-name=test python-path=/var/www/test/

See also: https://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi


Post a Comment for "WSGI: ImportError: No Module Named Hello (module In The Same Directory Of The Main .py File)"