Django的/阿帕奇/ mod_wsgi的:无模块命名导入库(Django / Apache /

2019-06-26 07:21发布

与过去两个月Django的开发服务器的工作后,时间终于移动到Apache + mod_wsgi的。

问题是,当我去我的网站(我们称之为junux),映射到Django应用程序的URL,事情似乎并不管用。 当运行开发服务器在服务器上的东西正常工作。

错误的底线,是给我在Apache的error_log:

导入错误:无法导入设置“junux_site.settings”(它是不是在sys.path中):无模块命名导入库

我知道这类似于对此事的许多其他问题(有这么多,我甚至不会说出来了这里),但我还没有找到答案。 我已阅读在移动到生产,包括Django的部署文档,mod_wsgi的指南,一些PYCON演示,整天被google搜索问题不少导游...

有趣的地段和下面精彩细节。

任何帮助将不胜感激。 提前致谢。


配置:

  • 阿帕奇2.2.15与在CentOS 6的mod_wsgi
  • Python的2.7.3从源代码编译
  • 该网站使用的virtualenv

这是错误页面apache的回报:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Apache/2.2.15 (CentOS) Server at junux.net Port 80

apache的error_log揭示了以下信息:

mod_wsgi (pid=22502): Create interpreter 'junux.net|/dev'.
mod_wsgi (pid=22502): Exception occurred processing WSGI script '/var/www/junux_dev/junux_site/wsgi.py'.
Traceback (most recent call last):
  File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
    self.load_middleware()
  File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:
  File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'junux_site.settings' (Is it on sys.path?): No module named importlib

相关wsgi.py

import os
import sys
import site

# use our virtual environment
SITE_DIR = os.path.dirname(__file__)
PROJECT_ROOT = os.path.dirname(SITE_DIR)
site_packages = os.path.join(PROJECT_ROOT, 'venv/lib/python2.7/site-packages')
site.addsitedir(os.path.abspath(site_packages))
sys.path.insert(0, SITE_DIR)
sys.path.insert(1, PROJECT_ROOT)

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

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

httpd.conf :(这里从默认的Apache配置文件的详细内容)

<VirtualHost *:80>
        ServerName junux.net
        ServerAlias junux.net
        ServerAdmin admin@junux.net

        WSGIScriptAlias /test /var/www/test/hello.py
        WSGIScriptAlias /dev /var/www/junux_dev/junux_site/wsgi.py

        <Directory /var/www/test >
        Order allow,deny
        Allow from all
        </Directory>

        <Directory /var/www/junux_dev >
        Options FollowSymLinks
        Order allow,deny
        Allow from all
        </Directory>

</VirtualHost>

LogLevel info

有一个WSGIScriptAlias/test ,以提供一个理智,检查mod_wsgi的确实有效。 它的作用。 当打开该网址(很简单)应用程序的工作(典型的Hello World)。

我已设置权限, chmod o+r在我的WSGI文件,并chmod o+rx对整个/var/www/junux_dev目录,如PYCON悉尼- 2010演示文稿指示refered从这里 。

Answer 1:

Python版本是mod_wsgi的编译反对? 看起来你可能具有系统上的多个Python的安装和虚拟环境是使用Python 2.7,但你的mod_wsgi的是对2.6编译。

上午立足于事实,即导入库是在Python 2.7只加了,所以如果mod_wsgi的被编译为2.6和使用基本安装这个猜测,那么将无法找到导入库。

运行检查:

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Installation_In_Use



文章来源: Django / Apache / mod_wsgi: No module named importlib