开发者

import of python/django modules fails on debian vps

开发者 https://www.devze.com 2023-01-26 07:20 出处:网络
debian vps with gigatux. using django/python with mod_wsgi and im using virtualenvs as i hope to be hosting a few different sites which may well be at different levels.

debian vps with gigatux. using django/python with mod_wsgi and im using virtualenvs as i hope to be hosting a few different sites which may well be at different levels.

im having an issue getting the site running, rig开发者_JS百科ht now i can't even do a syncdb as it refuses to import the django package that is inside the site-packages folder

I've got the statement below in my django.wsgi file which is called from the wsgi config line in apache2/sites-available/default

import sys
sys.path.append('/home/shofty/virtualenvs/sitename/lib/python2.5/site-packages')

and i've got quite a few packages in that folder.

however syncdb won't run.

now ive installed django on the vps without forcing it into a virtualenv, then i can run syncdb. but syncdb fails on the import of modules in installedapps that are in the site-packages but not installed on the vps. so i know that that statement above isnt working.

i appreciate there may be a more specialised place to ask this question, i just dont know it. tell me what that is if you know somewhere where this will get answered. i've got two days getting this vps running and to be honest, im ready to give up.


Mixing up environments won't help.

Clearly some packages are installed in the bundled python and some other in the virtualenv.

My suggestion, stick to virtualenv

And work on the virtualenv, always, by source /path/to/venv/bin/activate

Within the wsgi file, enable the virtualenv. You do that not by importing its site_packages, but by asking the mod_wsgi to use that python. You do that by the following command:

activate_this = '/path/to/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))


I worked on getting debian, apache, django, mod_wsgi, and virtualenvs to play nicely a couple weeks ago. Looking at the template I made for our wsgi files I'm using both 'site.addsitedir' and 'sys.path.append' where 'site.addsitedir' points to the site_package and 'sys.path.append' points to a copy of the application on the host. Here is what the first part of the jinja2 template looks like for django.wsgi

import sys
import os
import site

site.addsitedir('{{ site_package }}')
sys.path.append('{{ local_source }}')
...

'local_source' is something like '/home/jdoe/my_project' and 'site_package' is something like '/usr/local/lib/python2.6/site-packages'.

I remember have to play around with it a bit, and I also remember an issue with 'django.wsgi' and 'settings.py' having to be in the same directory. I hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号