"ImportError: No module named django" persists...

121 views
Skip to first unread message

Scott

unread,
Jan 15, 2008, 6:55:14 PM1/15/08
to Django users, nat...@playgroundblues.com, graham.d...@gmail.com
Thank you to anyone who may be of help...

PROBLEM:

ImportError: No module named django

MY SETTINGS:

/Working/django/django/__init__.py (file exists)
/Working/projects/ (my main project
folder)
/Working/projects/mysite ('mysite' project folder)
/usr/lib/python2.4/site-packages (my python packages folder)
(Permissions are 755 with owner:group = root:root)

httpd.conf directives are...

<Location "/mysite">
SetHandler python-program
PythonPath "['/Working/django','/Working/modules','/Working/
projects','/Working/projects/mysite'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
# PythonHandler mod_python.testhandler
PythonHandler django.core.handlers.modpython
PythonDebug On
</Location>

OTHER CLUES:

- Django imports just fine from command line python call with
$PYTHONPATH exported to same directories as location directive.
- If I put my django folder in /usr/lib/python2.4/site-packages/ it
works.
- A sym link from /Working/django/django to /usr/lib/python2.4/site-
packages/django does not work.
- Reference by PythonPath directive also is failing.
- Viewing testhandler output shows that my /Working/* directories are
getting into sys.path alright.

MY SYSTEM:

OS = { Red Hat Enterprise Linux 5 | RHEL 5 | RHEL5 }
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
Apache/2.2.3 (Red Hat) Server
mod_python.version '3.2.8'
Django VERSION = (0, 97, 'pre')


Thank you for looking.

Scott

1234

unread,
Jan 15, 2008, 7:39:16 PM1/15/08
to django...@googlegroups.com
django is in your sys.path?

2008/1/16, Scott <distan...@gmail.com>:

Scott

unread,
Jan 15, 2008, 9:48:59 PM1/15/08
to Django users
1234,

Yes, with these directives:

------------
<Location "/mysite">
SetHandler python-program
PythonPath "['/Working/django','/Working/modules','/Working/
projects','/Working/projects/mysite'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonHandler mod_python.testhandler
#PythonHandler django.core.handlers.modpython
PythonDebug On
</Location>
------------


Here's the output for the 'sys.path':

------------
Apache version Apache/2.2.3 (Red Hat)
Apache threaded MPM No (single thread MPM)
Apache forked MPM Yes, maximum 256 processes
Apache server root /etc/httpd
Apache document root /var/www/html
Apache error log /etc/httpd/logs/error_log (view last 100 lines)
Python sys.version 2.4.3 (#1, Dec 11 2006, 11:38:52) [GCC 4.1.1
20061130 (Red Hat 4.1.1-43)]
Python sys.path =

/Working/django
/Working/modules
/Working/projects
/Working/projects/mysite
/usr/lib/python24.zip
/usr/lib/python2.4
/usr/lib/python2.4/plat-linux2
/usr/lib/python2.4/lib-tk
/usr/lib/python2.4/lib-dynload
/usr/lib/python2.4/site-packages
/usr/lib/python2.4/site-packages/Numeric
/usr/lib/python2.4/site-packages/gtk-2.0

Python interpreter name server.mysite.com
mod_python.publisher available Yes
mod_python.psp available Yes
-------------

Any thoughts?

Scott

Graham Dumpleton

unread,
Jan 15, 2008, 11:58:47 PM1/15/08
to Django users
First verify Django is being picked up from where you think it is by
doing:

import django
print django.__file__

Second, ensure that the installed Django files have permissions that
would allow user that Apache may be running as to access it. That is,
if Apache is running as a service and the Django files are only
readable by you, it will not be able to load them.

Graham
> Python interpreter name server.mysite.commod_python.publisher available  Yesmod_python.psp available        Yes

Karen Tracey

unread,
Jan 16, 2008, 9:46:53 AM1/16/08
to django...@googlegroups.com
On Jan 15, 2008 6:55 PM, Scott <distan...@gmail.com> wrote:
MY SYSTEM:

OS = { Red Hat Enterprise Linux 5 | RHEL 5 | RHEL5 }
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
Apache/2.2.3 (Red Hat) Server
mod_python.version '3.2.8'
Django VERSION = (0, 97, 'pre')

From all the information you've posted it really seems like the apache process cannot access files under /Working, whereas it can access files under site-packages.  This despite the fact that the file permissions under /Working look like they should allow access by apache.  So what could be going on?  I've never used RHEL5, but I've read some about it and it includes SELinux (security-enhanced Linux).  Could this be getting in the way?  This page:

http://www.linuxtopia.org/online_books/rhel5/rhel5_administration/rhel5_sec-sel-admincontrol.html

list some commands to show the status of SELinux.  If you try them on your system and it's enabled/enforcing and restricting access to /Working, then that could explain the weird behavior you have described.  Fixing it would then require either disabling SELinux or changing the config to remove the restrictions on apache's access to /Working.

Karen

Marty Alchin

unread,
Jan 16, 2008, 10:02:31 AM1/16/08
to django...@googlegroups.com
On Jan 15, 2008 9:48 PM, Scott <distan...@gmail.com> wrote:
> /Working/django

Out of curiosity, what are the contents of this directory? Is this the
root of the django distribution (containing things like 'docs',
'tests' and another 'django' directory), or is this the django code
itself (containing things like 'core', 'db' and 'contrib')?

If it's the latter, that'll definitely cause you problems, since
Python only sees the *contents* of the directory, so you'd never be
able to "import django" in this manner. If that's the case, try just
using "/Working" and see if that helps. If it's the former, and it
does have a second "django" directory inside it, I don't know what to
suggest.

-Gul

Scott

unread,
Jan 16, 2008, 11:39:29 AM1/16/08
to Django users
@Graham:
It looks like it is a working django load. Also, the permissions are
the same as when they were able to load while in the python site
packages folder.
---------------
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print django.__file__
/Working/django/django/__init__.pyc
>>>
---------------


@Marty:
Here is the path to my django __init__.pyc file as output above in the
test requested by Graham: /Working/django/django/__init__.pyc


@Karen:
This sounds promising I'm digging into that and will post my findings.

Thank you for your responses, kind folks.

Scott

Scott

unread,
Jan 16, 2008, 5:19:18 PM1/16/08
to Django users, chadc...@gmail.com
Awesome, Karen, that was it! Thank you so much. Here's the fix for you
RHEL5 (Red Hat Enterprise Linux 5 | RHEL 5) users.

My working directory and subdirectories needed SELinux permission to
be used by apache/httpd so I ran this command:

[root]# chcon -R -t httpd_user_content_t /Working

See my solution reference here:
http://docs.fedoraproject.org/selinux-faq-fc3/index.html#id2825658

Thank you again to all that offered aid.

Scott
Reply all
Reply to author
Forward
0 new messages