views:

403

answers:

2

Hi, I've got problems on getting django to work on apache 2.2 with mod_wsgi. Django is installed and mod_wsgi too. I can even see a 404 page when accessing the path and I can login to django admin. But if I want to install the tagging module I get the following error:

 Traceback (most recent call last):
   File "setup.py", line 49, in <module>
  version_tuple = __import__('tagging').VERSION
   File "/home/jim/django-tagging/tagging/__init__.py", line 3, in <module>
  from tagging.managers import ModelTaggedItemManager, TagDescriptor
   File "/home/jim/django-tagging/tagging/managers.py", line 5, in <module>
  from django.contrib.contenttypes.models import ContentType
   File "/usr/lib/python2.5/site-packages/django/contrib/contenttypes/models.py", line 1, in <module>
  from django.db import models
   File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 10, in <module>
  if not settings.DATABASE_ENGINE:
   File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 269, in __getattr__
  self._setup()
   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup
  self._wrapped = Settings(settings_module)
   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__
  raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
 ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings

My httpd.conf:

 Alias /media/ /home/jim/django/mysite/media/

 <Directory /home/jim/django/mysite/media>
  Order deny,allow
  Allow from all
 </Directory>

 Alias /admin/media/ "/usr/lib/python2.5/site-packages/django/contrib/admin/media/"

 <Directory "/usr/lib/python2.5/site-packages/django/contrib/admin/media/">
  Order allow,deny
  Allow from all
 </Directory>

 WSGIScriptAlias /dj /home/jim/django/mysite/apache/django.wsgi

 <Directory /home/jim/django/mysite/apache>
  Order deny,allow
  Allow from all
 </Directory>

My django.wsgi:

import sys, os

sys.path.append('/home/jim/django')
sys.path.append('/home/jim/django/mysite')

os.chdir('/home/jim/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I try to get this to work since a few days and have read several blogs and answers here on so but nothing worked.

Edit:

Now I tried it with this blog post and my wsgi file now looks like this:

import sys
sys.path.insert(0, '/home/jim/django/mysite')
sys.path.insert(0, '/home/jim/django')

import settings

import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')

command.validate()

import django.conf
import django.utils

django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

admin is still working, but I'm getting the same error when I try to install the tagging module.

A: 

Have you read Graham Dumpleton's blog post on Django and WSGI? It does a pretty good job of describing some common configuration problems, and specifically touches on mysite.settings vs. settings.

UPDATE: Please read Graham Dumpleton's excellent comments below.

UPDATE 2: As both Graham and becomingGuru have pointed out, the problem is not with WSGI at all. It is instead a problem with your installation of django-tagging. Take becomingGuru's advice and use pip to install django-tagging.

Hank Gay
I'll try that, thank you
Jimbo
Hope it fixes your specific problem.
Hank Gay
Still got the same problem :/
Jimbo
Then you likely have a permissions problem. Apache runs as a special user and not you. Therefore the directories where Django site is, plus all parent directories down to that point, must be accessible to Apache user. If you have rwx------ on your home account then Apache will not be able to see inside of your account.
Graham Dumpleton
Alternatively if the site is working but only fails when adding this, then you possibly simply have introduced a syntax error in your settings file. Post the section of the settings file you modified.
Graham Dumpleton
Hmmm, no. Because the second WSGI import method imports settings in WSGI script file, if there was a syntax error in it, you should get different message. BTW, that blog post doesn't say to add '/home/jim/django' to sys.path, only the site directory itself. It shouldn't matter in this case though. Anyway, all doesn't matter, as just realised that original error message is not even from inside of mod_wsgi. It is from python being invoked on "setup.py" directly. Where are you doing that? Looks like you haven't set PYTHONPATH properly if executing on command line. The WSGI stuff is irrelevant.
Graham Dumpleton
I'm running the setup.py of the django-tagging module from inside the directory located in /home/jim/django-tagging/setup.py. The permissions of /home/jim/django and /home/jim/django-tagging as well as /usr/lib/python2.5/site-packages/django are set to rwxr-xr-x. The PYTHONPATH environment variable wasn't set. I set it to: /usr/lib/python2.5 but I keep having the problem
Jimbo
to understand it correctly as newbe django/linux user, just to get it right. The mysite.settings file does not exists on the filesystem. it's a 'link' to the settings.py in my mysite directory, right?
Jimbo
I also tried to set the PYTHONPATH to '/home/jim/django/mysite' but with no success
Jimbo
PYTHONPATH has to include parent directory of where your Django site is.
Graham Dumpleton
A: 

First,

  • Since your admin works, the setting with wsgi is good. Don't bother changing/editing it.

To ensure that it is not a Apache/mod-wsgi setting problem, you can run the development server from the production machine

python manage.py runserver 0:8080

Then point your browser to

http://yoursite.com:8080/

You must see exactly the same behaviour.

Then,

For debugging this problem:

  • On the python shell on your server, try import tagging. Clearly, from your traceback, import tagging is where it is raising an error and thats why, settings cannot be imported.

  • Then, Just delete the package containing tagging, and do a fresh install by the following command, which knows how to install packages, well.

.

sudo pip install django-tagging
Lakshman Prasad
import tagging does not work, even with the development server: Traceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named tagging
Jimbo
Jimbo: Thats exactly what I predicted. You can now read my answer carefully, to solve your problem!
Lakshman Prasad
never used pip before but it worked. don't know what caused the problem. I hope it was tagging specific so that I don't have the same problem with another package later on.. thank you
Jimbo