从virtualenv运行python3

时间:2013-09-11 15:51:26

标签: django python-3.x

我仍然无法理解apache如何理解他现在应该运行的python版本。

在virtualenv中我只安装python3.2,然后我将这些代码放在wsgi包装器上:

# -*- coding: utf-8 -*-
#!/virtualenvs/simpleboard/bin/python

import os, sys, site

my_virtualenv_path = "/virtualenvs/simpleboard/lib/python3.2/site-packages/"
# Add it to your PYTHONPATH


sys.path.insert(0, my_virtualenv_path)
site.addsitedir(my_virtualenv_path)

sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, '/www/django/simpleboard/simpleboard')
sys.path.insert(0, '/www/django/simpleboard')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "simpleboard.settings")

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

最后我在我的类代码的头部添加了这个标记,但是apache仍然运行2.7

Exception Location:     /www/django/simpleboard/account/views.py in rescale, line 386
Python Executable:  /usr/bin/python
Python Version:     2.7.3
Python Path:    
['../..',
 '/www/django/simpleboard',
 '/www/django/simpleboard/simpleboard',
 '/www/django/simpleboard/simpleboard',
 '/virtualenvs/simpleboard/lib/python3.2/site-packages/',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages']

Server time:    Wed, 11 Sep 2013 19:43:21 +0400

正如您所看到的,他因为它而运行2.7版本和回溯错误

1 个答案:

答案 0 :(得分:1)

您可以使用uwsgi(http://projects.unbit.it/uwsgi/wiki/VirtualEnv)的virtualenv支持。在你的uwsgi init脚本中为你的uwsgi命令添加“H / virtualenvs / simpleboard”。