Сбой wsgi.py с «Нет модуля с именем« django »» в virtualenv на Apache - PullRequest
0 голосов
/ 11 июня 2018

Я запускаю веб-приложение Django на сервере Amazon Linux EC2 и правильно установил и проверил Apache и mod_wsgi.Я сконфигурировал файл конфигурации Apache, как показано ниже, и проверил, что в Python загружены правильные пути, напечатав sys.path (показано в журнале ошибок), однако я продолжаю получать ошибку 500 с файлом wsgi.py, который завершается с ModuleNotFoundError: No module named 'django' ошибка.Я получаю ту же ошибку при использовании режима демона в конфигурационном файле apache.Чего мне не хватает?

Мой virtualenv находится на /var/www/html/test, а мое веб-приложение на /var/www/html/ai_demo_webapp/webapp (это местоположение моего manage.py файла).Я использую Apache 2.2.34 с pip-версией mod_wsgi и загрузил модуль wsgi в файле конфигурации apache как LoadModule wsgi_module "/home/ec2-user/.local/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so".

wsgi.py

import os
import sys

print(sys.path)

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webapp.settings")

application = get_wsgi_application()

Файл конфигурации Apache

WSGIPythonHome /var/www/html/test
WSGIPythonPath /var/www/html/ai_demo_webapp/webapp

<VirtualHost *:80>
WSGIScriptAlias / /var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py

<Directory /var/www/html/ai_demo_webapp/webapp/webapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>

Журнал ошибок Apache при перезапуске apache и доступе к сайту

[Mon Jun 11 05:01:46 2018] [notice] SIGHUP received.  Attempting to restart
[Mon Jun 11 05:01:46 2018] [notice] Digest: generating secret for digest authentication ...
[Mon Jun 11 05:01:46 2018] [notice] Digest: done
[Mon Jun 11 05:01:46 2018] [notice] Apache/2.2.34 (Unix) DAV/2 mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations
[Mon Jun 11 05:01:50 2018] [error] ['/var/www/html/ai_demo_webapp/webapp', '/var/www/html/test/local/lib64/python3.6/site-packages', '/var/www/html/test/local/lib/python3.6/site-packages', '/var/www/html/test/lib64/python3.6', '/var/www/html/test/lib/python3.6', '/var/www/html/test/lib64/python3.6/site-packages', '/var/www/html/test/lib/python3.6/site-packages', '/var/www/html/test/lib64/python3.6/lib-dynload', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6', '/usr/lib/python3.6', '/usr/lib64/python3.6/dist-packages', '/usr/lib/python3.6/dist-packages', '/usr/lib64/python3.6/lib-dynload']
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200] mod_wsgi (pid=27915): Failed to exec Python script file '/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py'.
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200] mod_wsgi (pid=27915): Exception occurred processing WSGI script '/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py'.
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200] Traceback (most recent call last):
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200]   File "/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py", line 27, in <module>
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200]     from django.core.wsgi import get_wsgi_application
[Mon Jun 11 05:01:50 2018] [error] [client 75.82.153.200] ModuleNotFoundError: No module named 'django'
[Mon Jun 11 05:01:51 2018] [error] ['/var/www/html/ai_demo_webapp/webapp', '/var/www/html/test/local/lib64/python3.6/site-packages', '/var/www/html/test/local/lib/python3.6/site-packages', '/var/www/html/test/lib64/python3.6', '/var/www/html/test/lib/python3.6', '/var/www/html/test/lib64/python3.6/site-packages', '/var/www/html/test/lib/python3.6/site-packages', '/var/www/html/test/lib64/python3.6/lib-dynload', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6', '/usr/lib/python3.6', '/usr/lib64/python3.6/dist-packages', '/usr/lib/python3.6/dist-packages', '/usr/lib64/python3.6/lib-dynload']
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200] mod_wsgi (pid=27919): Failed to exec Python script file '/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py'., referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200] mod_wsgi (pid=27919): Exception occurred processing WSGI script '/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py'., referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200] Traceback (most recent call last):, referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200]   File "/var/www/html/ai_demo_webapp/webapp/webapp/wsgi.py", line 27, in <module>, referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200]     from django.core.wsgi import get_wsgi_application, referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
[Mon Jun 11 05:01:51 2018] [error] [client 75.82.153.200] ModuleNotFoundError: No module named 'django', referer: http://ec2-54-149-122-177.us-west-2.compute.amazonaws.com/
...