【问题标题】:Django WSGI APACHE ModuleNotFoundError: No module named 'django'Django WSGI APACHE ModuleNotFoundError:没有名为“django”的模块
【发布时间】:2020-04-01 13:42:26
【问题描述】:

尝试在 ubuntu 服务器 18 上使用 apache 和 wsgi 部署 django 是一场噩梦,我创建了一个虚拟环境,安装了依赖项,多次重新启动 apache,但是 apache wsgi 在我的虚拟环境中找不到 django。 我可以运行 manage.py runserver 所以虚拟环境依赖是好的。 我的 venv 的 python 版本是 3.8

这是 apache 错误日志:

[Sun Dec 08 02:09:53.028651 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59496]     from django.core.wsgi import get_wsgi_application
[Sun Dec 08 02:09:53.028666 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59496] ModuleNotFoundError: No module named 'django'
[Sun Dec 08 02:09:53.335770 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497] mod_wsgi (pid=18902): Target WSGI script '/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py' cannot be loaded as Python module.
[Sun Dec 08 02:09:53.335820 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497] mod_wsgi (pid=18902): Exception occurred processing WSGI script '/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py'.
[Sun Dec 08 02:09:53.335893 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497] Traceback (most recent call last):
[Sun Dec 08 02:09:53.335915 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497]   File "/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py", line 17, in <module>
[Sun Dec 08 02:09:53.335919 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497]     from django.core.wsgi import get_wsgi_application
[Sun Dec 08 02:09:53.335933 2019] [wsgi:error] [pid 18902:tid 140235648796416] [remote 186.116.79.225:59497] ModuleNotFoundError: No module named 'django'
[Sun Dec 08 02:09:53.665977 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498] mod_wsgi (pid=18902): Target WSGI script '/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py' cannot be loaded as Python module.
[Sun Dec 08 02:09:53.666021 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498] mod_wsgi (pid=18902): Exception occurred processing WSGI script '/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py'.
[Sun Dec 08 02:09:53.666097 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498] Traceback (most recent call last):
[Sun Dec 08 02:09:53.666120 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498]   File "/var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py", line 17, in <module>
[Sun Dec 08 02:09:53.666124 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498]     from django.core.wsgi import get_wsgi_application
[Sun Dec 08 02:09:53.666139 2019] [wsgi:error] [pid 18902:tid 140235766351616] [remote 186.116.79.225:59498] ModuleNotFoundError: No module named 'django'

我不知道该怎么办,

这是我的 /etc/apache2/sites-available/000-default.conf 文件:

<VirtualHost *:80>

        Alias /static /var/www/iotconfigserver/IOT_config_rest/static

        <Directory /var/www/iotconfigserver/IOT_config_rest/static>
                Require all granted
        </Directory>

        <Directory /var/www/iotconfigserver/IOT_config_rest/IOT_config_rest >
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess IOT_config_rest python-home=/var/www/iotconfigserver/venv python-path=/var/www/iotconfigserver/IOT_config_r$        
    WSGIProcessGroup IOT_config_rest
        WSGIScriptAlias / /var/www/iotconfigserver/IOT_config_rest/IOT_config_rest/wsgi.py
</VirtualHost>

感谢任何试图提供帮助的人

【问题讨论】:

    标签: python django apache


    【解决方案1】:

    我可以通过将 python venv 降级到 3.6 来部署,但我仍然不知道为什么

    【讨论】:

    • 这是因为 mod_wsgi 模块是用 python3.6 编译的,因此使用 python3.6 库(其中未安装 django)而不是在 py3.8 上运行的 venv
    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 2017-08-15
    • 1970-01-01
    • 2021-11-17
    • 2020-01-15
    • 2019-03-08
    • 2021-08-06
    相关资源
    最近更新 更多