Reputation: 29767
I have installed python 2.7 on centos.
I have created and activated a virtualenv associated with this interpreter.
My path looks like this:
/home/ec2-user/django-venv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
When I hit my website i get the following error indicating that it is using the old version of python:
mod_wsgi (pid=19386): Exception occurred processing WSGI script '/var/www/html/-django//wsgi.py'.
Traceback (most recent call last):
File "/var/www/html/-django//wsgi.py", line 23, in <module>
from django.core.wsgi import get_wsgi_application
File "/usr/lib/python2.6/site-packages/django/core/wsgi.py", line 2, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
from django import http
File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict,
File "/usr/lib/python2.6/site-packages/django/http/request.py", line 11, in <module>
from django.conf import settings
File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 9, in <module>
import importlib
ImportError: No module named importlib
I created the the virtualenv like this:
virtualenv --python=/usr/local/bin/python2.7 django-venv
I then activated it like this:
source django-venv/bin/activate
When i initiate "which python" I get the following output:
~/django-venv/bin/python
My apache httpd.conf entry looks like this:
Alias /static/ /var/www/html/django/shared/static/
<Directory /var/www/html/django/shared/static/>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /var/www/html/django/wsgi.py
WSGIPythonPath /var/www/html/django
<Directory /var/www/html/django>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
But I still get the error above that it is using the old python version of 2.6
How can I have my site use this virtualenv which points to the correct place?
Upvotes: 0
Views: 557
Reputation: 1218
I just use the wsgi.py
file generated by manage.py startproject
and then put something like this in my httpd conf file:
WSGIScriptAlias / /full/path/to/wsgi.py
WSGIPythonPath /full/path/to/django/project:/full/path/to/django-venv/lib/python2.7/site-packages
The official docs cover this.
Upvotes: 1
Reputation: 599630
If you just run it in the shell, that only affects that shell session, and doesn't even persist between logins, let alone affecting any system-wide services like Apache.
Normally you would put something in your wsgi.py:
activate_this = '/path/to/virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
Upvotes: 0