skip to Main Content

I am trying to run my Django Project using Apache.

When I launch Apache I receive an ‘Internal Server Error’, inspecting the logs I have found that it fails to execute the wsgi.py for my project and throws the errors below.

The error presented says there is No module named 'localassets', i.e. the projectname.

mod_wsgi (pid=5128): Failed to exec Python script file 'C:/Env/localassets/localassets/wsgi.py'., referer: http://localhost/
mod_wsgi (pid=5128): Exception occurred processing WSGI script 'C:/Env/localassets/localassets/wsgi.py'., referer: http://localhost/
Traceback (most recent call last):r, referer: http://localhost/
   File "C:/Env/localassets/localassets/wsgi.py", line 16, in <module>r, referer: http://localhost/
     application = get_wsgi_application()r, referer: http://localhost/
   File "C:\Env\Lib\site-packages\django\core\wsgi.py", line 12, in get_wsgi_applicationr, referer: http://localhost/
     django.setup(set_prefix=False)r, referer: http://localhost/
   File "C:\Env\Lib\site-packages\django\__init__.py", line 19, in setupr, referer: http://localhost/
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)r, referer: http://localhost/
   File "C:\Env\Lib\site-packages\django\conf\__init__.py", line 102, in __getattr__r, referer: http://localhost/
    self._setup(name)r, referer: http://localhost/
   File "C:\Env\Lib\site-packages\django\conf\__init__.py", line 89, in _setupr, referer: http://localhost/
     self._wrapped = Settings(settings_module)r, referer: http://localhost/
   File "C:\Env\Lib\site-packages\django\conf\__init__.py", line 217, in __init__r, referer: http://localhost/
     mod = importlib.import_module(self.SETTINGS_MODULE)r, referer: http://localhost/
   File "C:\Program Files\Python310\Lib\importlib\__init__.py", line 126, in import_moduler, referer: http://localhost/
     return _bootstrap._gcd_import(name[level:], package, level)r, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 1050, in _gcd_importr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 1027, in _find_and_loadr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlockedr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removedr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 1050, in _gcd_importr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 1027, in _find_and_loadr, referer: http://localhost/
   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlockedr, referer: http://localhost/
 ModuleNotFoundError: No module named 'localassets'r, referer: http://localhost/

httpd.conf

LoadFile "C:/Program Files/Python310/python310.dll"
LoadModule wsgi_module "C:/Env/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "C:/Program Files/Python310"
WSGIScriptAlias / "C:/Env/localassets/localassets/wsgi.py"
WSGIPythonPath "C:/Env/Lib/site-packages"

<Directory "C:/Env/localassets/localassets/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "C:/Env/localassets/localassets/static"
<Directory "C:/Env/localassets/localassets/static">
    Require all granted
</Directory>

Inspecting the wsgi.py file I don’t see any issues here either.

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'localassets.settings')

application = get_wsgi_application()

It seems as though I am missing something in wsgi.py but I am unsure as to what I am missing for this to work correctly?

2

Answers


  1. In your python environment you have to install the library. You can install projectname with following command:

    pip install projectname or pip3 install projectname
    After the installation of projectname python library, ModuleNotFoundError: No module named 'projectname' error will be solved.
    If the error is still there, check your imports – you might have to import from either django_backend or user_profile

    Login or Signup to reply.
  2. just add the apps folder to sys.path in wsgi.py:

    import os
    import sys
    
    sys.path.insert(0, 'C:/Env/localassets')
    
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'localassets.settings')
    
    application = get_wsgi_application()
    

    btw. you seem to have the virtual env folder mixed with your app. I would recommend to separate like

    project_folder
       env
       localassets
          localassets
             wsgi.py
    
    etc.
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search