The article is going to discuss about how to solve the error happened at once a web-based application executed. The web-based application is powered by Django framework written in Python programming language. The article written to discuss on how to solve the error as shown below based on the error log generated :
[Wed Feb 28 22:41:12.779197 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] mod_wsgi (pid=17877): Target WSGI script '/home/user/apps/user/src/wsgi.py' cannot be loaded as Python module. [Wed Feb 28 22:41:12.779222 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] mod_wsgi (pid=17877): Exception occurred processing WSGI script '/home/user/apps/user/src/wsgi.py'. [Wed Feb 28 22:41:12.779241 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] Traceback (most recent call last): [Wed Feb 28 22:41:12.779259 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/home/user/apps/user/src/wsgi.py", line 9, in [Wed Feb 28 22:41:12.779325 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] application = get_wsgi_application() [Wed Feb 28 22:41:12.779335 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application [Wed Feb 28 22:41:12.779350 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] django.setup() [Wed Feb 28 22:41:12.779364 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup [Wed Feb 28 22:41:12.779373 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) [Wed Feb 28 22:41:12.779381 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__ [Wed Feb 28 22:41:12.779389 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] self._setup(name) [Wed Feb 28 22:41:12.779393 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 43, in _setup [Wed Feb 28 22:41:12.779400 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] self._wrapped = Settings(settings_module) [Wed Feb 28 22:41:12.779404 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 99, in __init__ [Wed Feb 28 22:41:12.779411 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] mod = importlib.import_module(self.SETTINGS_MODULE) [Wed Feb 28 22:41:12.779415 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module [Wed Feb 28 22:41:12.779608 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] __import__(name) [Wed Feb 28 22:41:12.779628 2018] [wsgi:error] [pid 17877] [remote 127.0.0.1:1959] ImportError: No module named app.settings
The error itself is shown in the bottom of the error log generated which is “ImportError: No module named app.settings”. Basically, in wsgi.py file, the module named app.settings cannot be found, either it is not define in the environment variable path or it is not recognized because the path containing file wsgi.py cannot be accessed.
So, in order to solve the problem, the following is the actual step for solving the error above. Just define the path where the wsgi.py file located inside the file wsgi.py as follows :
sys.path = ["/home/user/apps/user/src/",]
After defining the path, re-execute the web-based application to see the results.