我可以在1个域上使用2个不同版本的Python的2个Django站点吗?

时间:2015-06-17 16:07:40

标签: python django apache virtualenv mod-wsgi

我有一个使用服务器默认Python(2.6.6)的Django项目,我有一个新项目,我想使用Python 2.7,并将它放在虚拟环境中。

这是错误:

data-bind="text: (array1[$index()-1]) ? array1[$index()-1].property : ''"

的httpd.conf:

[client 64.136.119.142] Traceback (most recent call last):
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]   File "/var/www/venv/googleclicks/googleclicks/wsgi.py", line 12, in <module>
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]     from django.core.wsgi import get_wsgi_application
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]   File "/var/www/venv/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]     from django.utils.version import get_version
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]   File "/var/www/venv/lib/python2.7/site-packages/django/utils/version.py", line 7, in <module>
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]     from django.utils.lru_cache import lru_cache
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]   File "/var/www/venv/lib/python2.7/site-packages/django/utils/lru_cache.py", line 28
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]      fasttypes = {int, str, frozenset, type(None)},
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]                      ^
[Wed Jun 17 00:00:32 2015] [error] [client 64.136.119.142]  SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:0)

虽然您可以使用mod_wsgi在单个版本的Python下托管多个域/站点,但据我所知您不能运行多个版本的Python,因为mod_wsgi必须针对单个版本进行编译。

对于Centos 6,首先按照此处的说明购买Python 2.7.x或3.x到另一个位置(make altinstall):

https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4

然后,您应该能够启动Python并检查您的版本:

python2.7 --version

接下来,创建一个virtualenv(我使用virtualenvwrapper;强烈推荐):

mkvirtualenv yourproject -p python2.7

然后,为新的Python版本安装mod_wsgi(4.2.8是我在我的流浪盒中测试过的最新版本;你可能想尝试更新的版本):

wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.2.8.tar.gz"
tar -xzf '4.2.8.tar.gz'
cd ./mod_wsgi-4.2.8
./configure --with-python=python2.7
make
make install

最后,如果一切正常,请确保在此行中指向正确的virtualenv:

WSGIScriptAlias /gclicks /var/www/venv/gc/gc/wsgi.py process-group=gclicks

答案 1 :(得分:-1)

试试this,我不确定不同的python版本,但你可以在一个域下拥有多个网站。