我尝试使用apache部署Django应用程序,收到以下错误
[Fri Oct 08 07:55:44.393237 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Target WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py' cannot be loaded as Python module.
[Fri Oct 08 07:55:44.393281 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Exception occurred processing WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py'.
[Fri Oct 08 07:55:44.393408 2021] [wsgi:error] [pid 12424:tid 140450959271680] Traceback (most recent call last):
[Fri Oct 08 07:55:44.393430 2021] [wsgi:error] [pid 12424:tid 140450959271680] File "/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py", line 12, in <module>
[Fri Oct 08 07:55:44.393435 2021] [wsgi:error] [pid 12424:tid 140450959271680] from django.core.wsgi import get_wsgi_application
[Fri Oct 08 07:55:44.393446 2021] [wsgi:error] [pid 12424:tid 140450959271680] ModuleNotFoundError: No module named 'django'
我的Apache虚拟主机
<VirtualHost *:80>
DocumentRoot /home/preinstall/hx_preinstaller
ErrorLog ${APACHE_LOG_DIR}/preinstall_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/preinstall/hx_preinstaller/hx_preinstaller>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/preinstall/hx_preinstaller>
Require all granted
</Directory>
WSGIDaemonProcess preinstall python-path=/home/preinstall/hx_preinstaller:/home/preinstall/.local/lib/python3.6/site-packages
WSGIProcessGroup preinstall
WSGIPassAuthorization On
WSGIScriptAlias / /home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py
</VirtualHost>
我该怎么办?..
2条答案
按热度按时间lyfkaqu11#
可能是python版本不匹配,或者您没有正确地将python路径添加到appache.conf。去检查这篇文章了解更多关于这个错误-> link
qzlgjiam2#
可能下面的解决方案可以为您工作,如果您的服务器使用旧的Python版本,如3.6,并且您更新到3.11,则可能会发生这种情况。以下是我推荐的步骤
1.激活虚拟环境conda环境(如果你使用anaconda更新python)。
1.在该环境中运行“pip install mod_wsgi”
1.调整/apache 2/etc/loadmodule.conf从myvirtualenv中加载新的mod_wsgi
1.重新启动httpd