简体   繁体   English

如何更改我的Django项目使用的Python?

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

I have 2 versions installed in my server. 我的服务器中安装了2个版本。 I used virtualenv to install Python 2.7. 我使用virtualenv来安装Python 2.7。

I am using WSGI to deploy my project. 我正在使用WSGI来部署我的项目。

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

My http.conf is like that. 我的http.conf就是这样的。

python -V gives python -V给出

Python 2.7.3 Python 2.7.3

But in my projects Debug window, it says Django is using 2.6.8. 但在我的项目Debug窗口中,它表示Django正在使用2.6.8。 Where am I wrong? 我哪里错了?

UPDATE: Here is my wsgi file 更新:这是我的wsgi文件

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: Python版本:2.6.8 Python路径:
['/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'] ['/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-package /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-package / 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-package','/ usr / lib / python2.6 / site-package / setupupols -0.6c11-py2.6.egg-info','/ var / www / html']

In my error_log of httpd: 在我的httpd的error_log中:

[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] [错误] python_init:Python版本不匹配,预计'2.6.7',找到'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] [错误] python_init:Python可执行文件找到'/ 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'. [Tue Jul 10 20:51:29 2012] [error] python_init:正在使用的Python路径'/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”。

If I understand the question correctly, you are trying to configure the application's wsgi script to use a specific virtualenv. 如果我正确理解了这个问题,那么您正在尝试将应用程序的wsgi脚本配置为使用特定的virtualenv。

If that is the case check out modwsgi's docs: http://code.google.com/p/modwsgi/wiki/VirtualEnvironments 如果是这种情况,请查看modwsgi的文档: 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. 我会尝试为你做TLDR,但它在那个链接上写得非常好,我无法做到公道。

The mod_wsgi module must be compiled for the specific Python major/minor version you want to use. 必须针对要使用的特定Python主要/次要版本编译mod_wsgi模块。 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. 您无法使用WSGIPythonHome强制针对Python 2.6编译的mod_wsgi使用使用Python 2.7构建的Python虚拟环境。

If you use Buildout you can control which version of python is being used directly in the configuration file. 如果使用Buildout,您可以直接在配置文件中控制使用哪个版本的python。

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

相关问题 如何使用 Django 在 Python 中查看我的 HTML 页面 - How can I view my HTML page in Python using Django 如何在整个 django 项目中更改 django_spanner 应用程序的行为? 当我在我的 django 应用程序中使用 2 个数据库时 - How to change the behaviour of django_spanner application on entire django project? As I am using 2 databases inside my django application 如何配置后台进程,该进程在django项目中按指定的时间间隔运行python脚本 - How can i configure a background process which runs a python script in my django project at specified intervals of time 如何识别Django项目的CSS - How can I identify my css to my django project 为什么我不能使用PostgreSQL运行Django项目? - Why can't I run my Django project using PostgreSQL? 如何将 CSS 添加到我的 Django 项目网站? - How can I add CSS to my Django project website? 如何在Django项目中设置唯一的邮件注册? - How can i set unique mail registration in my Django project? 如何在我的 Django 项目之外拥有一个模板文件夹 - How can I have a template folder outside my Django project 如何在Django FeinCMS项目中将ModelAdmins子类化? - How can I subclass my ModelAdmins in a Django FeinCMS project? 如何在Django项目中使用静态文件? - How can I get static files to work in my Django project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM