Hello All,

I would appreciate expert advice about getting PYTHONPATH to work with
Apache and mod_python for django. When I shell into the server I can
get all modules to load without error (as root). This includes django,
custom modules (people) and my projects (mysite).

BASH snippet:
----------------------

[root]# python
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
>>> import people
>>> import mysite
>>>

----------------------

No errors.
But, when I try to load the test site through a browser I get the
following error:

http://xxx.xxx.xxx.xxx/mysite/ error:
-----------------------

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
287, in HandlerDispatch
    log=debug)

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
461, in import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named django

-----------------------



I've read as much as I can find here in 
http://groups.google.com/group/django-users
, at http://www.djangoproject.com/documentation/ , at http://www.djangobook.com/
, and on Google. I'll break the issue down further.

-----------------------
SYSTEM INFO:
-----------------------

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')

-----------------------
FILE SYSTEM:
-----------------------

/var/www/html/                           (Curr Web Dir)

/usr/lib/python2.4/site-packages/    (Python packages/modules dir)

/Working/django/django               (Django source)
/Working/django/django/__init__.py   (file exists)

/Working/projects/                   (my main project folder)
/Working/projects/mysite             ('mysite' project folder)

/Working/modules/                    (apps folder)
/Working/modules/people/             (Basic People django app folder)

-----------------------
ENVIRONMENT VARIABLES
-----------------------

While logged in as root via ssh/bash

/etc/profile.d/pythonpath.sh is included by /etc/profile and loads by
default for any user. See the contents below, which defines and
exports $PYTHONPATH and appends my django 'bin' to $PATH.

[root]# cat /etc/profile.d/pythonpath.sh
export PYTHONPATH=/Working/django:/Working/modules:/Working/projects
export PATH=/Working/django/django/bin/:$PATH

[root]# echo $PYTHONPATH
/Working/django:/Working/modules:/Working/projects

-----------------------



NOW THE INTERESTING PART...


I created a sym link...

[root]# ln -s /Working/django/ /usr/lib/python2.4/site-packages/django

That didn't fix it, so I cleared that one out and tried straight to
the django folder.

[root]# rm -f /usr/lib/python2.4/site-packages/django
[root]# ln -s /Working/django/django/ /usr/lib/python2.4/site-packages/
django

When listing the two directories /Working/django/django and /usr/lib/
python2.4/site-packages/django they are identical.

---------------

[root]# ls /usr/lib/python2.4/site-packages/django

lrwxrwxrwx 1 root root 22 Jan 14 14:24 /usr/lib/python2.4/site-
packages/django -> /Working/django/django/

[root]# ls /Working/django/django/ /usr/lib/python2.4/site-packages/
django/

/usr/lib/python2.4/site-packages/django/:
total 168K
drwxr-xr-x 20 root root 4.0K Jan 14 11:02 ./
drwxr-xr-x  8 root root 4.0K Jan 14 11:27 ../
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 bin/
drwxr-xr-x  7 root root 4.0K Jan 14 11:02 conf/
drwxr-xr-x 20 root root 4.0K Jan 14 11:02 contrib/
drwxr-xr-x  8 root root 4.0K Jan 14 11:02 core/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 db/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 dispatch/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 forms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 http/
-rw-r--r--  1 root root  299 Jan 14 11:02 __init__.py
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 middleware/
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 newforms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 oldforms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 shortcuts/
drwxr-xr-x  6 root root 4.0K Jan 14 11:02 .svn/
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 template/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 templatetags/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 test/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 utils/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 views/

/Working/django/django/:
total 168K
drwxr-xr-x 20 root root 4.0K Jan 14 11:02 ./
drwxr-xr-x  8 root root 4.0K Jan 14 11:27 ../
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 bin/
drwxr-xr-x  7 root root 4.0K Jan 14 11:02 conf/
drwxr-xr-x 20 root root 4.0K Jan 14 11:02 contrib/
drwxr-xr-x  8 root root 4.0K Jan 14 11:02 core/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 db/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 dispatch/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 forms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 http/
-rw-r--r--  1 root root  299 Jan 14 11:02 __init__.py
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 middleware/
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 newforms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 oldforms/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 shortcuts/
drwxr-xr-x  6 root root 4.0K Jan 14 11:02 .svn/
drwxr-xr-x  4 root root 4.0K Jan 14 11:02 template/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 templatetags/
drwxr-xr-x  3 root root 4.0K Jan 14 11:02 test/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 utils/
drwxr-xr-x  5 root root 4.0K Jan 14 11:02 views/

---------------

That didn't fix it either. So I placed the django code straight into
the Python Packages directory.

[root]# rm -f /usr/lib/python2.4/site-packages/django
[root]# cp -f /Working/django/django /usr/lib/python2.4/site-packages/

That worked. It could find django but died at the first module/
project. So I copied the modules (people, etc.) and project (mysite)
to the Python Packages directory.

[root]# cp -f /Working/modules/* /usr/lib/python2.4/site-packages/
[root]# cp -f /Working/projects/mysite /usr/lib/python2.4/site-
packages/

With all of my modules huddled (scared and alone) in my Python
Packages folder... BOOM! "WELCOME TO DJANGO". It worked.

I can't see this being the intended requirement. I would like to be
able to go back

----------

Is it a permissions issue? Note that when moving django to the Python
Packages dir I didn't change the permissions. All django core files
were permissioned and owned the same as when sym linked to from the
same directory.

Here are my permissions:

drwxr-xr-x root   root   /usr/lib/python2.4/site-packages/
drwxr-xr-x root   root   /var/www/html/
drwxr-xr-x root   root   /Working/django/django/
drwxr-xr-x root   root   /Working/modules/
drwxr-xr-x root   root   /Working/projects/

At one point as a bold attempt against a permissions problem I chmod'd
all file to 777 and back, and chown'd all files to root, apache,
nobody, mysite then back to root.

Is it an Apache lack of having PYTHONPATH correct? To test that, can I
output the $PYTHONPATH to the browser before or as part of the error
output to my browser? (I can't 'su apache' to test the environment)

---------

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

---------


Is there an Apache or Python main config file that needs to be set a
certain way to allow my PYTHONPATH to be accessed or exported for
Apache.


I KNOW THAT'S A LOT OF INFO, BUT...

A ton of info here, I know, but I've spent so much time
troubleshooting this I'm thinking one who can help may spot my problem
easily with enough information available check against what I've
tried. I've seen many posts with similar errors here in Google's
Django user-group but none of the fixes seemed to help me get up and
running.

I thank anyone whose taken the time to analyse my situation. Djangians
really are the best community!

Scott








--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to