Django WSGI APACHE ModuleNotFoundError:没有名为“ django”的模块

时间:2019-12-08 03:29:28

标签: python django apache

尝试在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>

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

1 个答案:

答案 0 :(得分:0)

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