簡體   English   中英

500 內部服務器錯誤 mod_wsgi apache "importerror: No Module named 'django'

[英]500 internal server error mod_wsgi apache "importerror: No Module named 'django'

運行 django 和 apache2/mod_wsgi 的問題。 我不斷收到 500 內部服務器錯誤。 我嘗試了許多修復組合,但都沒有奏效。 任何幫助是極大的贊賞。 這是我的設置:

Ubuntu 16.04
django 1.10.5
apache 2.4.18
python 3.4(virtualenv)
libapache2-mod-wsgi-py3 

我的文件夾結構是:

/home/user/site/venv (virtualenv folder)
    bin
    include
    lib

/home/user/site/mysite
    |- manage.py
    static
    mysite
        |__init__.py
        |settings.py
        |urls.py
        |wsgi.py

站點配置文件

<VirtualHost *:80>
WSGIDaemonProcess myproject python-home=/home/user/site/venv python-path=/home/user/site/mysite
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/site/mysite/mysite/wsgi.py

        Alias /static /home/user/site/mysite/static
        <Directory /home/user/site/mysite/static>
            Require all granted
        </Directory>

        <Directory /home/user/site/mysite/mysite>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>


</VirtualHost>

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

apache2/error.log

[mpm_event:notice] [pid 8908:tid 140560009164672] AH00491: caught SIGTERM, shutting down
[wsgi:warn] [pid 9047:tid 139761898837888] mod_wsgi: Compiled for Python/3.5.1+.
[wsgi:warn] [pid 9047:tid 139761898837888] mod_wsgi: Runtime using Python/3.5.2.
[mpm_event:notice] [pid 9047:tid 139761898837888] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[core:notice] [pid 9047:tid 139761898837888] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] [pid 9049:tid 139761776183040] mod_wsgi (pid=9049): Target WSGI script '/home/user/site/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 9049:tid 139761776183040] mod_wsgi (pid=9049): Exception occurred processing WSGI script '/home/user/site/mysite/mysite/wsgi.py'.
[wsgi:error] [pid 9049:tid 139761776183040] Traceback (most recent call last):
[wsgi:error] [pid 9049:tid 139761776183040]   File "/home/user/site/mysite/mysite/wsgi.py", line 12, in <module>
[wsgi:error] [pid 9049:tid 139761776183040]     from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 9049:tid 139761776183040] ImportError: No module named 'django'

我已授予以下文件夾的權限:

sudo chown -R www-data:www-data /home/user/site/venv
sudo chown -R www-data:www-data /home/user/site/mysite

任何幫助或批評,我都希望提前感謝您。

所以在一些激烈的頭部撞牆之后。 事實證明,我需要為我使用的 python 版本編譯我自己的 mod_wsgi。 我正在使用 ubuntu libapache2-mod-wsgi-py3 的標准 repo,它被編譯為與 python3.5.2 一起使用,如我的 error.log 中所示。

我去這里是為了最新版本: mod_wsgi_releases

安裝mod_wsgi時一定要使用下面的命令

.configure --with-python=/your/virtualenv/bin/python(your python_verion here)

嘗試使用這樣的東西。 只是為了確認, myproject是用戶組嗎?

WSGISocketPrefix /var/run/wsgi
WSGIPythonPath /home/user/site/venv/lib/python2.7/site-packages
WSGIDaemonProcess ec2-user processes=1
WSGIProcessGroup ec2-user
WSGIScriptAlias / /home/user/site/mysite/mysite/wsgi.py

嘗試在您的虛擬環境中使用which django-admin 如果這與您希望使用的位置不同,請在您的虛擬環境中安裝 django。 或者在您的虛擬環境中嘗試pip freeze > requirements.txt以查看 django 實際上是否存在。

有同樣的問題,我通過卸載 gunicorn 並在我的項目中通過虛擬環境登錄時重新安裝來修復它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM