Django+Apache+Virtualenv+WSGI(无法更改主解释器)

2024-06-14 06:08:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有python2.7.3和任何站点包的virtualenv。 在这个服务器上——Python2.6.6。我需要python2.7.3作为主解释器

在wsgi.py文件:

import os
import sys
import site


# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/mts_report/mts_report_project')
sys.path.append('/var/www/mts_report/mts_report_project/mts_report_project')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mts_report_project.settings.local'

# Activate your virtual env
activate_env="/home/aaodegov/virtual_envs/basic_env_2/bin/activate_this.py"
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

apache配置:

^{pr2}$

检查python版本(在debug-django模式下):

Python Executable:  /usr/bin/python
Python Version: 2.6.6
Python Path:    
['/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7',
 '/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7/site-packages',
 '/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/pymodules/python2.6',
 '/var/www/mts_report/mts_report_project',
 '/var/www/mts_report/mts_report_project/mts_report_project']

因此,Django使用来自virtualenv的站点包,而使用来自系统的主解释器。 如何使用virtualenv的解释器(2.7.3)? 谢谢。在


Tags: theimportreportenvprojecthomevirtualenvlib
2条回答

在apache配置的开头添加

WSGIPythonHome PATH_TO_YOUR_2.7.3_PYTHON

<VirtualHost *:80>
...

请注意,您可能还需要添加以下内容:

^{pr2}$

也会改变

python-path=/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7:/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7/site-packages

python-path=/home/aaodegov/virtual_envs/basic_env_2/lib/python2.7/site-packages

你不需要在中引用virtualenvwsgi.py在

昨天问题解决了。 对遇到类似问题的人有用。 mod_vsgi不是为python 2.7编译的。 谢谢大家的回答。在

首先,安装apache2 threaded dev 然后,使用enable shared编译PYTHON。这很重要。在

./configure  enable-shared  prefix=/usr/local/python-2.7.3
make
make install
ln -s /usr/local/python-2.7.3/bin/python2.7 /usr/bin/python2.7.3

找不到libpython2.7.so.1.0问题:

^{pr2}$

用python2.7.3编译MOD\WSGI

./configure  with-python=/usr/bin/python2.7.3
make
make install

重新启动apache:

service apache2 restart

相关问题 更多 >