WSGI 错误:目标 WSGI 脚本无法作为 Python 模块加载

问题描述 投票:0回答:2

我正在尝试使用 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>

我该怎么办?..

django apache mod-wsgi wsgi wsgiserver
2个回答
0
投票

可能是 python 版本不匹配,或者您没有正确地将 python 路径添加到 appache.conf 。 去查看这篇文章以了解有关此错误的更多信息 ->>> link


0
投票

以下解决方案可能适合您 如果您的服务器使用旧的 python 版本(例如 3.6)并且您更新到了 3.11,则可能会发生这种情况。这些是我推荐的以下步骤

  1. 激活virtual env conda环境(如果你使用anaconda更新python)。
  2. 在该环境中运行“pip install mod_wsgi”
  3. 调整 /apache2/etc/loadmodule.conf 以从 myvirtualenv 内部加载新的 mod_wsgi
  4. 重新启动httpd
© www.soinside.com 2019 - 2024. All rights reserved.