[英]500 internal server error mod_wsgi apache "importerror: No Module named 'django'
Issues running django and apache2/mod_wsgi.运行 django 和 apache2/mod_wsgi 的问题。 I keep getting 500 Internal Server Error.
我不断收到 500 内部服务器错误。 I have tried many combinations of fixes to which none have worked.
我尝试了许多修复组合,但都没有奏效。 Any help is greatly appreciated.
任何帮助是极大的赞赏。 This is my setup:
这是我的设置:
Ubuntu 16.04
django 1.10.5
apache 2.4.18
python 3.4(virtualenv)
libapache2-mod-wsgi-py3
My folder structure is:我的文件夹结构是:
/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
site.conf站点配置文件
<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 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 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'
I have given the permissions to the folders below:我已授予以下文件夹的权限:
sudo chown -R www-data:www-data /home/user/site/venv
sudo chown -R www-data:www-data /home/user/site/mysite
Any help or criticism I would love thank you in advance.任何帮助或批评,我都希望提前感谢您。
So after some intense head bashing against the wall.所以在一些激烈的头部撞墙之后。 It turns out I needed to compile my own mod_wsgi for the version of python I was using.
事实证明,我需要为我使用的 python 版本编译我自己的 mod_wsgi。 I was using the standard repo for ubuntu libapache2-mod-wsgi-py3 which is compiled to use with python3.5.2 as it shows in my error.log.
我正在使用 ubuntu libapache2-mod-wsgi-py3 的标准 repo,它被编译为与 python3.5.2 一起使用,如我的 error.log 中所示。
I went here for the most up to date version : mod_wsgi_releases我去这里是为了最新版本: mod_wsgi_releases
be sure to use the command below when installing mod_wsgi安装mod_wsgi时一定要使用下面的命令
.configure --with-python=/your/virtualenv/bin/python(your python_verion here)
Try using something like this.尝试使用这样的东西。 Just to confirm, is
myproject
the user group ?只是为了确认,
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
try which django-admin
in your virtual env.尝试在您的虚拟环境中使用
which django-admin
。 If this is different location than the location you desire it to be to work with, install django in your virtual env.如果这与您希望使用的位置不同,请在您的虚拟环境中安装 django。 Or try
pip freeze > requirements.txt
in your virtual env to see django is actually there.或者在您的虚拟环境中尝试
pip freeze > requirements.txt
以查看 django 实际上是否存在。
有同样的问题,我通过卸载 gunicorn 并在我的项目中通过虚拟环境登录时重新安装来修复它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.