简体   繁体   English

我在virtual-env中的python是2.7,但是Django调试屏幕显示了系统的2.6.6

[英]My python in virtual-env is 2.7 but the Django debug screen shows the system's 2.6.6

So inside of my virtual env, if I activate it and type python , version 2.7 is opened, as it should. 因此,在我的虚拟环境中,如果我将其激活并键入python ,则将打开2.7版。

When an error arises in Django, it shows version 2.6 which is the system default. 当Django中发生错误时,它会显示2.6版,这是系统默认值。 Here is what my Apache configuration looks like: 这是我的Apache配置:

<VirtualHost *:80>
    ServerName www.mysite.com
    ErrorLog /var/www/virtualenv-2.7/django-error-log
    Alias /static/ /var/www/virtualenv-2.7/mysite/mainapp/static/
    WSGIDaemonProcess mysite python-path=/var/www/virtualenv-2.7/mysite:/var/www/virtualenv-2.7/lib/python2.7/site-packages
    WSGIProcessGroup mysite
    WSGIScriptAlias / /var/www/virtualenv-2.7/mysite/mysite/wsgi.py

    <Directory /var/www/virtualenv-2.7>
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

WSGISocketPrefix /var/run/wsgi
WSGIPythonPath /var/www/virtualenv-2.7/mysite:var/www/virutalenv-2.7/lib/python2.7/site-packages

My wsgi.py: 我的wsgi.py:

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

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

When I service httpd restart , this is what is put in the apache error logs: 当我为service httpd restart ,这是apache错误日志中的内容:

[Mon Jan 19 20:19:03 2015] [notice] caught SIGTERM, shutting down
[Mon Jan 19 20:19:04 2015] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Mon Jan 19 20:19:04 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Jan 19 20:19:04 2015] [notice] Digest: generating secret for digest authentication ...
[Mon Jan 19 20:19:04 2015] [notice] Digest: done
[Mon Jan 19 20:19:04 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations

Any idea why Django does not use 2.7 found in the virtual env? 知道为什么Django不使用虚拟环境中的2.7吗?

The mod_wsgi module is compiled against the system version of Python; mod_wsgi模块是针对Python的系统版本编译的; the clue is in the startup message: 提示在启动消息中:

                           mod_wsgi library version
                           vvvvvvvvvvvv
Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured
                                        ^^^^^^^^^^^^
                                        Python version

To fix this, you can either compile mod_wsgi against the version of Python you need, or use the WSGIPythonHome configuration directive: 要解决此问题,您可以针对所需的Python版本编译mod_wsgi,或使用WSGIPythonHome配置指令:

Used to indicate to Python when it is initialised where its library files are installed. 用于在初始化时向Python指示其库文件的安装位置。 This should be defined where the Python executable is not in the PATH of the user that Apache runs as, or where a system has multiple versions of Python installed in different locations in the file system, especially different installations of the same major/minor version, and the installation that Apache finds in its PATH is not the desired one. 应该在Python可执行文件不在Apache所运行用户的PATH中,或者系统在文件系统中的不同位置(尤其是同一主/次版本的不同安装)中安装了多个Python版本的系统中定义此文件,并且Apache在其PATH中找到的安装不是所需的安装。

This directive can also be used to indicate a Python virtual environment created using a tool such as virtualenv, to be used for the whole of mod_wsgi. 此伪指令还可用于指示使用诸如virtualenv之类的工具创建的Python虚拟环境,该环境将用于整个mod_wsgi。

In your Apache configuration, add the following and then reload the server: 在您的Apache配置中,添加以下内容,然后重新加载服务器:

WSGIPythonHome /var/www/virtualenv-2.7/lib/python2.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM