我可以在 1 个域上使用 2 个不同版本的 Python 拥有 2 个 Django 站点吗?
Can I have 2 Django sites using 2 different version of Python on 1 domain?
我有 1 个使用服务器默认 Python (2.6.6) 的 Django 项目,我有一个新项目想使用 Python 2.7,并将其放在虚拟环境中。
这是错误:
[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
httpd.conf:
<VirtualHost *:80>
ServerName www.mydomain.com
ErrorLog /var/mail/django-error-log
Alias /static/ /var/www/django/t/tUrls/static/
WSGIScriptAlias /t /var/www/django/t/t/wsgi.py
WSGIScriptAlias /gclicks /var/www/venv/gc/gc/wsgi.py process-group=gclicks
WSGIDaemonProcess gclicks python-path=/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
#WSGIPythonPath /var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
<Location /gclicks>
WSGIProcessGroup gclicks
</Location>
# WSGIDaemonProcess gclicks python-path=/var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
# WSGIProcessGroup gclicks
<Directory /var/www/django>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
WSGIPythonPath /var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
#WSGIPythonHome /var/www/virtualenv-2.7
WSGISocketPrefix /var/run/wsgi
尝试 this,我不确定不同的 python 版本,但您可以在一个域下拥有多个站点。
虽然您可以在 Python 和 mod_wsgi 的单个版本下托管多个域/站点,但据我所知,您不能拥有多个 Python [=39] 版本=] 因为 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 是我在 vagrant box 中测试过的最新版本;您可能想尝试更新的版本):
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 个使用服务器默认 Python (2.6.6) 的 Django 项目,我有一个新项目想使用 Python 2.7,并将其放在虚拟环境中。
这是错误:
[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
httpd.conf:
<VirtualHost *:80>
ServerName www.mydomain.com
ErrorLog /var/mail/django-error-log
Alias /static/ /var/www/django/t/tUrls/static/
WSGIScriptAlias /t /var/www/django/t/t/wsgi.py
WSGIScriptAlias /gclicks /var/www/venv/gc/gc/wsgi.py process-group=gclicks
WSGIDaemonProcess gclicks python-path=/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
#WSGIPythonPath /var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
<Location /gclicks>
WSGIProcessGroup gclicks
</Location>
# WSGIDaemonProcess gclicks python-path=/var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
# WSGIProcessGroup gclicks
<Directory /var/www/django>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
WSGIPythonPath /var/www/django/t:/var/www/venv/gc:/var/www/venv/lib/python2.7/site-packages
#WSGIPythonHome /var/www/virtualenv-2.7
WSGISocketPrefix /var/run/wsgi
尝试 this,我不确定不同的 python 版本,但您可以在一个域下拥有多个站点。
虽然您可以在 Python 和 mod_wsgi 的单个版本下托管多个域/站点,但据我所知,您不能拥有多个 Python [=39] 版本=] 因为 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 是我在 vagrant box 中测试过的最新版本;您可能想尝试更新的版本):
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