4

I have 1 Django project using the server's default Python (2.6.6) and I have a new project that I want to use Python 2.7, and have it in a virtual env.

This is the error:

[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
User
  • 23,729
  • 38
  • 124
  • 207
  • Why can't you simply upgrade your 2.6 site to use 2.7? There are no backwards incompatibilities between minor Python versions. – Daniel Roseman Jun 17 '15 at 17:18
  • @DanielRoseman because everyone told me not to change the server default – User Jun 17 '15 at 17:19
  • 1
    Don't change the server default - that's for sure. However, you can install Python 2.7 to an alternate location (such as /usr/local/python27) and create a virtualenv against that version of Python. Then, point mod_wsgi to use your virtualenv. – FlipperPA Jun 17 '15 at 20:56
  • @DanielRoseman Oops, I read your comment wrong. Yes, I could upgrade the old site to 2.7. – User Jun 17 '15 at 22:24

2 Answers2

0

While you can host multiple domains / sites under a single version of Python with mod_wsgi, as far as I know you can not have multiple versions of Python running since mod_wsgi has to be compiled against a single version.

For Centos 6, first follow the instructions here to buy Python 2.7.x or 3.x to an alternative location (make altinstall):

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

Then, you should be able to fire up Python and check your version:

python2.7 --version

Next, create a virtualenv (I use virtualenvwrapper; highly recommended):

mkvirtualenv yourproject -p python2.7

Then, install mod_wsgi for the new Python version (4.2.8 is the latest I've tested in my vagrant box; you may want to try a more recent version):

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

Finally, if everything worked, ensure you point to the correct virtualenv in this line:

WSGIScriptAlias /gclicks /var/www/venv/gc/gc/wsgi.py process-group=gclicks
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • Ok, can you expand your answer so I can upgrade the old site to 2.7 and make them all work properly? – User Jun 17 '15 at 22:34
  • Sure - what Linux distro are you running? My workplace is a RedHat shop (unfortunately), so I have easy instruction for RedHat/CentOS, but they can be easily adapted to another distro and I'd be happy to help. While you're doing this, Django and most of its key packages are available for Python 3; you may want to consider the upgrade to Python 3 while you're doing this work. If you'd like to consider this, please also include the packages / apps you're using with Django. – FlipperPA Jun 18 '15 at 10:00
  • Centos 6. I decided to move the 2.6.6 into the virtualenv. It seemed a good idea according to the first comment on the question above. – User Jun 18 '15 at 16:32
  • 1
    Instructions have been added. Good luck! – FlipperPA Jun 18 '15 at 17:44
-1

Try this, I am not sure about different python version but you can have multiple sites under one domain.

Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61