django - apache2 python 3.4.3 ubuntu 错误 wsgi no module named

标签 django python-3.x ubuntu mod-wsgi

我尝试使用 python 3.4 在 apache2 中部署 Django,但发送错误 500。

apache 错误日志:

[Sat May 13 15:56:53.638802 2017] [mpm_event:notice] [pid 3610:tid 140692947613568] AH00489: Apache/2.4.12 (Ubuntu) mod_wsgi/4.3.0 Python/3.4.3+ configured -- resuming normal operations
[Sat May 13 15:56:53.638897 2017] [core:notice] [pid 3610:tid 140692947613568] AH00094: Command line: '/usr/sbin/apache2'
[Sat May 13 15:56:56.622523 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] mod_wsgi (pid=3613): Target WSGI script '/var/www/html/reportado-plataforma/reportalo/wsgi.py' cannot be loaded as Python module.
[Sat May 13 15:56:56.622610 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] mod_wsgi (pid=3613): Exception occurred processing WSGI script '/var/www/html/reportado-plataforma/reportalo/wsgi.py'
[Sat May 13 15:56:56.622646 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] Traceback (most recent call last):
[Sat May 13 15:56:56.622842 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259]   File "/var/www/html/reportado-plataforma/reportalo/wsgi.py", line 12, in <module>
[Sat May 13 15:56:56.622851 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259]     from django.core.wsgi import get_wsgi_application
[Sat May 13 15:56:56.622876 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] ImportError: No module named 'django'

我安装了
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
我的虚拟主机:
WSGIScriptAlias / /var/www/html/reportado-plataforma/reportalo/wsgi.py
WSGIDaemonProcess reportalo python-path=/var/www/html/reportado-plataforma:/root/env/lib/python3.4/site-packages
WSGIProcessGroup reportalo
WSGIPassAuthorization On

虚拟主机目录:
<Directory /var/www/html/reportado-plataforma/reportalo>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

我的环境:
appdirs==1.4.3
Django==1.11.1
django-cors-headers==2.0.2
django-filter==1.0.2
django-geoposition==0.3.0
django-location-field==2.0.3
djangorestframework==3.6.2
djangorestframework-gis==0.11.1
Markdown==2.6.8
olefile==0.44
packaging==16.8
Pillow==4.1.1
psycopg2==2.7.1
pyparsing==2.2.0
pytz==2017.2
six==1.10.0
uWSGI==2.0.15

最佳答案

Apache 运行您的代码的用户不太可能看到 /root 下的任何内容。目录。通常只有 root可以看到那个目录。将您的应用程序 Python 虚拟环境放在其他地方。

另请阅读:

  • http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

  • 有关使用 mod_wsgi 设置 Python 虚拟环境的推荐方法。使用python-home如记录而不是 python-path .

    关于django - apache2 python 3.4.3 ubuntu 错误 wsgi no module named,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43957567/

    相关文章:

    django - 无法分配 '1' : Comment. 用户必须是用户实例

    django - 从所有用户删除 session key

    jquery - 通过 jQuery ajax 调用将值列表传递给 django View

    excel - 未应用 OpenPyXL 文本换行

    ubuntu - 从 mysqldump 恢复 MySQL 架构

    python - 如何返回 django 中的调用 View ?

    python - 如何将 Python tkinter canvas postscript 文件转换为 PIL 可读的图像文件?

    Python 从包中安装子包

    ubuntu - ImageMagick比较:从PSNR结果中忽略白色匹配

    ubuntu - 系统重启后 Docker 不显示任何容器或图像