i have a problem with virtualenvs and django. Apparently i just dont get how they are supposed to work.
I installed python 2.7.3 ucs2 in /opt/bin/python and it works just fine I installed virtualenv and virtualenvwrapper and created virtual environment named py273ucs2 so when i type workon py273ucs2 i get correct virtual environment.
when i create python script with
#!/home/alan/python/virtualenvs/py273ucs2/bin/python
import sys
print sys.maxunicode
i get 65535 which is correct for ucs2 python.
at same time i have no idea how to use correct virtualenvironment for my django app so i could use ucs2 python not ucs4 one. I tried creating one test project with virtualenvwrapper.django thinking that its wsgi file or manage.py would give me hints about how to start wsgi script with correct environment - no such luck.
I found this site: http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/
which basically (in addition to other things that i already did) tells me to add this into my wsgi file :
site.addsitedir('/srv/python-environments/saltycrane/lib/python2.5/site-packages')
which in my case is:
site.addsitedir('/home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages')
Tried - no luck. Then there is such page: http://www.gyford.com/phil/writing/2011/06/27/virtualenv-webfaction.php In addition to last page it suggests i add:
activate_this = os.path.expanduser("~/.virtualenvs/my_env_name/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
which in my case is:
activate_this = os.path.expanduser("/home/alan/python/virtualenvs/py273ucs2/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
again no luck.. view
def base(request):
return HttpResponse(sys.version+' maxunicode ' +str(sys.maxunicode))
prints out python version 2.7.2 and maxunicode 1114111 not 65535.
Then there is this message here at stackoverflow: How does django work with virtualenv? which suggests i add params in httd.conf - also tried and also not working.
So honestly - im not getting this. Perhaps the version is supposed to remain 2.7.2 not become 2.7.3... then whats the point of virtualenvs... Or im doing something wrong and not getting something from those examples. I also checked wsgi wiki about virtualevns:
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
and modified my httpd.conf to:
WSGIPythonHome /home/alan/python/virtualenvs/py273ucs2
WSGIPythonPath /home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages
WSGIDaemonProcess printer user=alan group=alan processes=5 threads=5 python-path=/home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages
WSGIProcessGroup printer
WSGIScriptAlias / /home/alan/projects/printer/printer.wsgi
Nothing. Still see python 2.7.2 in view...
could someone help me out please :)
Alan
Edit1: answer to comments:
1) I have to install/compile new mod_wsgi if i want to use virtualenvironment? why?
2) if i do:
alan@alan:~$ workon py273ucs2
(py273ucs2)alan@alan:~$ cd projects/printer/
(py273ucs2)alan@alan:~/projects/printer$ python manage.py runserver
Validating models...
0 errors found
Django version 1.3, using settings 'printer.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[08/Jul/2012 05:01:00] "GET / HTTP/1.1" 200 68
then my view shows me:
2.7.3 (default, May 16 2012, 10:58:59) [GCC 4.6.1] maxunicode 65535
Edit2: Thanks to the help of Graham Dumpleton at modwsgi google group i managed to install mod_wsgi for ucs2 python (https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg).
But when i start this site i still get
2.7.2+ (default, Oct 4 2011, 20:41:12) [GCC 4.6.1] maxunicode 1114111
not
2.7.3 (default, Jul 9 2012, 13:32:29) [GCC 4.6.1] maxunicode 65535
Btw apache error log prints out this:
[Mon Jul 09 14:13:19 2012] [warn] mod_wsgi: Compiled for Python/2.7.3. [Mon Jul 09 14:13:19 2012] [warn] mod_wsgi: Runtime using Python/2.7.2+.
Final edit:
There were several problems with how the mod_wsgi was supposed to be installed. You can find out all necessary info when you follow this link : https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg.
But after those problems the point was that the way Ubuntu python installation is made it conflicts with other pythons (not the best explanation probably but you will find very good explanation by Graham Dumpleton if you follow the link above). Virtual python and mod_wsgi started all working when i removed libapache2-mod-python package. It caused other problems, but those problems are caused by the way ubuntu and its python package are set up.
So if you are ubuntu user and happen to find same problem, then this page and Graham Dupmpletons Huge efforts will probably help you too.
Duplicate of:
https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg
Issue documented at:
http://code.google.com/p/modwsgi/wiki/InstallationIssues#Mixing_32_Bit_And_64_Bit_Packages
Use '--enable-shared' when configuring/installing Python.