On 29 December 2010 13:46, Young <[email protected]> wrote:
> Hi Graham,
>
> Thanks a lot for the quick help. However it still fails even though I
> tried every possible combinations. I also checked the permissions but
> I couldn't find any wrong permission settings.
>
> From your comment below, I now guess my problem is due to the
> different environment variable settings between the root account and
> my account. As I mentioned before my service runs well with django dev
> server. I think when I run django dev server, it runs with my
> environment variable settings including PYTHONPATH which includes
> mysite and mysite's parent directory. However when I run apache2
> server, it runs with the root account's environment variable settings
> which doesn't include PYTHONPATH.
>
> I tried to insert mysite(/dfs/mysite) and mysite's parent directory(/
> dfs) into the root account's environment variable settings by adding
> "export PYTHONPATH=$PYTHONPATH:/dfs:/dfs/mysite" in the file /etc/
> profile and /etc/bashrc, but it didn't work. They didn't appear when I
> checked with "import sys" and "print sys.path" in the shell executed
> by the command "sudo python".

It won't as PYTHONPATH from root account will not propagate through
Apache startup.

> I also tried your manual which says how to add path in the django.wsgi
> script. When I printed sys.path in the script, the result included
> mysite and mysite's parent directory, but it also failed with "No
> module named sphene.community". One thing very weird is importing
> works without any error when I type the content in the wsgi script
> line by line in the python shell.

Please provide me the exact output from running the following:

  echo $PYTHONPATH

The run command line Python and inside of Python shell do:

  import sys

  print sys.version
  print sys.prefix
  print sys.path

  import sphene
  print sphene.__file__

  import sphene.community
  print sphene.community.__file__

For both the directories containing those __file__ items, do:

  ls -las /some/path

Also do this for all directories back up to root file system.

> My apache2 version is:
> Server version: Apache/2.2.16 (Ubuntu)
> Server built:   Nov 18 2010 21:18:34
>
> And my wsgi script is: ======================================
> import sys
>
> path1 = '/dfs'
> if path1 not in sys.path:
>    sys.path.append(path1)
>
> path2 = '/dfs/mysite'
> if path2 not in sys.path:
>    sys.path.append(path2)
>
> print sys.path

Add:

  print sys.version
  print sys.prefix

  import spene
  import sphene.community

Send me the full output of paths and version plus the error message
from Apache error logs.

By sending me actual output then I can evaluate it and not have to
guess whether it is what is expected.

Graham

> import settings
>
> import django.core.management
> django.core.management.setup_environ(settings)
> utility = django.core.management.ManagementUtility()
> command = utility.fetch_command('runserver')
>
> import sphene.community
> 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()
> ===========================================================
>
> Thanks for reading long email and I really appreciate your help.
>
> Young
>
> On Dec 27, 6:53 pm, Graham Dumpleton <[email protected]>
> wrote:
>> Whoops. I should have said to add it after any
>> sys.path/site.addsitedir stuff you do to set up Python module search
>> path.
>>
>> If when you restart Apache and try to access application, if the
>> loading of the WSGI script file fails on that import, then it means
>> that you have a sys.path or permissions issue.
>>
>> So, just before the import line, if it still fails, add:
>>
>>   import sys
>>   print >> sys.stderr, "PYTHONPATH", sys.path
>>
>> Then get what is printed from Apache error log file and double check
>> whether parent directory where 'sphene' is installed is listed in
>> sys.path.
>>
>> If it isn't, the parent directory where 'sphene' is installed needs to
>> be added, or you need to fix up how it is being added.
>>
>> Find out where 'sphene' is installed by running command line Python and 
>> doing:
>>
>>   import sphene
>>   print sphene.__file__
>>
>> The parent directory then is:
>>
>>   import os
>>   print os.path.dirname(os.path.dirname(sphene.__file__))
>>
>> If the directory is listed in sys.path, then it is going to be a
>> permissions issue.
>>
>> That is, the user that Apache is running your code as doesn't have
>> permission to access some directory down to where sphene is installed,
>> or perhaps even the code of sphene itself.
>>
>> Graham
>>
>> On 28 December 2010 13:36, Young <[email protected]> wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Hi Graham,
>>
>> > Thanks for the help. However the problem still occurs even though I
>> > added the line in the script.
>>
>> > Young
>>
>> > On Dec 26, 5:44 pm, Graham Dumpleton <[email protected]>
>> > wrote:
>> >> At the start of the WSGI script file add:
>>
>> >>   import sphene.community
>>
>> >> Does that work and then cause latter problem to go away or does it fail.
>>
>> >> Graham
>>
>> >> On 25 December 2010 00:23, Young <[email protected]> wrote:
>>
>> >> > Hi,
>>
>> >> > I've been configuring mod-wsgi for days but with no luck. My site runs
>> >> > well on Django dev server but doesn't work on Apache/mod_wsgi. I read
>> >> > Graham's nice blog post and it was very helpful to understand how
>> >> > Django dev server internally works. However it couldn't help to solve
>> >> > my problem as mine is somewhat complicated.
>>
>> >> > My site consists of 3 parts: my app, SCT app(wiki/forum,
>> >> >http://sct.sphene.net/wiki/show/Start/) and jpype module. Though my
>> >> > code solely runs well on Apache/mod_wsgi but it doesn't with other
>> >> > modules.
>>
>> >> > As my site runs well on Django dev server and both errors below are
>> >> > something like "class/module not found", I guess the error is related
>> >> > with path problems. However when I printed sys.path, it contained both
>> >> > '/dfs/mysite' and '/dfs'.
>>
>> >> > Any comments will be appreciated. Thanks in advance and Merry
>> >> > Christmas:)
>>
>> >> > -Young
>>
>> >> > My machine is:
>> >> > ###############################################################
>> >> > - Ubuntu server 10.10 64bit
>> >> > - Using DFS
>> >> > - Python 2.6.6
>> >> > - Django 1.2.3
>> >> > - mod_wsgi 3.3
>>
>> >> > Simplified directory structure is:
>> >> > #################################################
>> >> > /dfs/mysite/myapp : directory for my app
>> >> > /dfs/mysite/apache : directory for mod_wsgi script
>> >> > /dfs/mysite/sphene : director for SCT app
>> >> > /dfs/mysite/build/classes/com/mysite/myjava/Abc.Class : directory for
>> >> > JAVA class running on jpype
>>
>> >> > /etc/apache2/httpd.conf is:
>> >> > #####################################################
>> >> > Alias /site_media/ /dfs/mysite/site_media/
>> >> > <Directory /dfs/mysite/site_media>
>> >> >    Order deny,allow
>> >> >    Allow from all
>> >> > </Directory>
>>
>> >> > LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
>> >> > WSGIScriptAlias / /dfs/mysite/apache/django.wsgi
>> >> > <Directory /dfs/mysite/apache>
>> >> >    Order deny,allow
>> >> >    Allow from all
>> >> > </Directory>
>>
>> >> > /dfs/mysite/apache/django.wsgi is:
>> >> > ###############################################
>> >> > import sys
>> >> > path1 = '/dfs'
>> >> > if path1 not in sys.path:
>> >> >    sys.path.append(path1)
>> >> > path2 = '/dfs/mysite'
>> >> > if path2 not in sys.path:
>> >> >    sys.path.append(path2)
>>
>> >> > 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()
>>
>> >> > Jpype error is:
>> >> > ################################################################
>> >> > java.lang.ExceptionPyRaisable at /service/abc/
>> >> > java.lang.Exception: Class com.mysite.myjava.Abc not found
>>
>> >> > The Apache error.log is:
>> >> > #########################################################
>> >> > [Fri Dec 24 04:25:59 2010] [notice] Apache/2.2.16 (Ubuntu) mod_wsgi/
>> >> > 3.3 Python/2.6.6 configured -- resuming normal operations
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] mod_wsgi
>> >> > (pid=6180): Target WSGI script '/dfs/mysite/apache/django.wsgi' cannot
>> >> > be loaded as Python module.
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] mod_wsgi
>> >> > (pid=6180): Exception occurred processing WSGI script '/dfs/mysite/
>> >> > apache/django.wsgi'.
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] Traceback
>> >> > (most recent call last):
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/dfs/
>> >> > mysite/apache/django.wsgi", line 18, in <module>
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > command.validate()
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/core/management/base.py",
>> >> > line 249, in validate
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > num_errors = get_validation_errors(s, app)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/core/management/
>> >> > validation.py", line 28, in get_validation_errors
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]     for
>> >> > (app_name, error) in get_app_errors().items():
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 146, in get_app_errors
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > self._populate()
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 61, in _populate
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > self.load_app(app_name, True)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 76, in load_app
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > app_module = import_module(app_name)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35,
>> >> > in import_module
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > __import__(name)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] ImportError:
>> >> > No module named sphene.community
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] mod_wsgi
>> >> > (pid=6181): Target WSGI script '/dfs/mysite/apache/django.wsgi' cannot
>> >> > be loaded as Python module.
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] mod_wsgi
>> >> > (pid=6181): Exception occurred processing WSGI script '/dfs/mysite/
>> >> > apache/django.wsgi'.
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] Traceback
>> >> > (most recent call last):
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/dfs/
>> >> > mysite/apache/django.wsgi", line 18, in <module>
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > command.validate()
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/core/management/base.py",
>> >> > line 249, in validate
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > num_errors = get_validation_errors(s, app)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/core/management/
>> >> > validation.py", line 28, in get_validation_errors
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]     for
>> >> > (app_name, error) in get_app_errors().items():
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 146, in get_app_errors
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > self._populate()
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 61, in _populate
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > self.load_app(app_name, True)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/db/models/loading.py", line
>> >> > 76, in load_app
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > app_module = import_module(app_name)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]   File "/usr/
>> >> > local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35,
>> >> > in import_module
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121]
>> >> > __import__(name)
>> >> > [Fri Dec 24 12:26:10 2010] [error] [client 76.169.74.121] ImportError:
>> >> > No module named sphene.community
>>
>> >> > --
>> >> > You received this message because you are subscribed to the Google 
>> >> > Groups "modwsgi" group.
>> >> > To post to this group, send email to
>>
>> ...
>>
>> read more »
>
> --
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/modwsgi?hl=en.
>
>

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

Reply via email to