2 years ago
#44235
youstra
Module wsgi error when deploying Django app on apache
I had developped an application using Django (DRF). And I try to deploy it on a server. After following some tutorials on Internet, I got this error :
mod_wsgi (pid=27182): Failed to exec Python script file '/my/django/project/path/myProjectName/wsgi.py'.
mod_wsgi (pid=27182): Exception occurred processing WSGI script '/my/django/project/path/myProjectName/wsgi.py'.
Traceback (most recent call last):
File "/my/django/project/path/myProjectName/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
File "/my/django/project/path/venv/lib/python3.9/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/my/django/project/path/venv/lib/python3.9/site-packages/django/utils/version.py", line 1, in <module>
import datetime
File "/usr/lib/python3.9/datetime.py", line 12, in <module>
import math as _math
ModuleNotFoundError: No module named 'math'
I had checked on some forums but I didn't find a solution to solve my problem. It seems that the problem comes from wsgi module, which is already installed when I was configure the server using this command:
sudo apt install libapache2-mod-wsgi-py3
This is my V-host config:
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
# Available loglevels: trace8, ..., trace1, debug, info, no
ErrorLog /my-django/project/path/error.log
CustomLog /my-django/project/path/access.log combined
ServerName my-domaine.com
ServerAlias www.my-domaine.com
DocumentRoot /my-django/project/path
Alias /static /my-django/project/path/static
<Directory /my-django/project/path/static>
Require all granted
</Directory>
Alias /media /my-django/project/path/media
<Directory /my-django/project/path/media>
Require all granted
</Directory>
<Directory /my-django/project/path/myProject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /my-django/project/path/myProject/wsgi.py
WSGIDaemonProcess django_app python-path=/my-django/project/path python-home=/my-django/project/path/venv
WSGIProcessGroup django_app
</VirtualHost>
What can I do to solve this problem ?
Edit
When I run python manage.py runserver 0.0.0.0:8000 on my server
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/my-django-project-path/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/my-django-project-path/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 144, in inner_run
handler = self.get_handler(*args, **options)
File "/my-django-project-path/venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "/my-django-project-path/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 70, in get_handler
return get_internal_wsgi_application()
File "/my-django-project-path/venv/lib/python3.9/site-packages/django/core/servers/basehttp.py", line 48, in get_internal_wsgi_application
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'myDjangoProject.wsgi.application' could not be loaded; Error importing module.
django
apache
mod-wsgi
0 Answers
Your Answer