wsgi.py在apache的virtualenv中以“没有名为'django'的模块”失败

时间:2018-06-11 05:53:02

标签: python django apache virtualenv mod-wsgi

我在Amazon Linux EC2服务器上运行Django webapp并正确安装并验证了Apache和mod_wsgi。我按如下所示配置了Apache配置文件,并通过打印sys.path验证了在Python中加载了正确的路径(显示在错误日志中),但是,wsgi.py文件失败后,我一直收到500错误出现ModuleNotFoundError: No module named 'django'错误。在apache配置文件中使用守护进程模式时出现相同的错误。我错过了什么?

我的virtualenv位于/var/www/html/test,我的网址位于/var/www/html/ai_demo_webapp/webapp(这是我manage.py文件的位置)。我正在使用带有mod_wsgi的pip版本的Apache 2.2.34,并将wsgi模块作为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"加载到apache配置文件中。

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/

0 个答案:

没有答案