How can I change the Python that my Django project is using?

I have 2 versions installed in my server. I used virtualenv to install Python 2.7.

I am using WSGI to deploy my project.

WSGIPythonPath /home/ENV/lib/python2.7/site-packages
WSGIScriptAlias / /var/www/html/my_project/wsgi.py

My http.conf is like that.

python -V gives

Python 2.7.3

But in my projects Debug window, it says Django is using 2.6.8. Where am I wrong?

UPDATE: Here is my wsgi file

import os
import sys
sys.path.append('/var/www/html')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Python Version: 2.6.8 Python Path:
['/home/ENV/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/home/ENV/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/home/ENV/lib/python2.7/site-packages/Django-1.4-py2.7.egg', '/home/ENV/lib/python2.7/site-packages', '/usr/lib/python2.6/site-packages/pip-1.1-py2.6.egg', '/usr/lib/python2.6/site-packages/django_transmeta-0.6.7-py2.6.egg', '/usr/lib/python2.6/site-packages/ipython-0.13-py2.6.egg', '/usr/lib/python2.6/site-packages/virtualenv-1.7.2-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/var/www/html']

In my error_log of httpd:

[Tue Jul 10 20:51:29 2012] [error] python_init: Python version mismatch, expected '2.6.7', found '2.6.8'. [Tue Jul 10 20:51:29 2012] [error] python_init: Python executable found '/usr/bin/python'. [Tue Jul 10 20:51:29 2012] [error] python_init: Python path being used '/usr/lib64/python26.zip:/usr/lib64/python2.6/:/usr/lib64/python2.6/plat-linux2:/usr/lib64/python2.6/lib-tk:/usr/lib64/python2.6/lib-old:/usr/lib64/python2.6/lib-dynload'.


The mod_wsgi module must be compiled for the specific Python major/minor version you want to use. You cannnot use WSGIPythonHome to force a mod_wsgi compiled against Python 2.6 to use a Python virtual environment constructed using Python 2.7.


If I understand the question correctly, you are trying to configure the application's wsgi script to use a specific virtualenv.

If that is the case check out modwsgi's docs: http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

I'd try to TLDR it for you, but its very well written at that link and I wouldn't be able to do it justice.


如果你使用Buildout,你可以控制在配置文件中直接使用哪个版本的python。

链接地址: http://www.djcxy.com/p/23344.html

上一篇: 在Google地图上动态加载KML地标

下一篇: 我该如何更改我的Django项目正在使用的Python?