mod_wsgi import python modile placed in a folder

40 views
Skip to first unread message

badc0re

unread,
Apr 12, 2012, 3:59:05 PM4/12/12
to mod...@googlegroups.com
the modules are working if they are in the same folder but i created the folder SE_controller and append the path for it but it is not working.

Code:

# -*- coding: utf-8 -*-
import sys, os
sys.path.append('/home/baddc0re/Desktop/htdocs') # the folder with the modules needer
sys.path.append('/opt/hypertable/0.9.5.6/lib/py')
sys.path.append('/opt/hypertable/0.9.5.6/lib/py/gen-py')
sys.path.append('/usr/lib/python2.7/site-packages')      
from SE_controller.SE_text_parser import * #the error
from SE_controller.SE_text_query import * #the error
from hypertable.thriftclient import *
from hyperthrift.gen.ttypes import *  
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!>'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
   
 
    return [output]


The error:

[Thu Apr 12 19:04:38 2012] [error] [client 127.0.0.1] mod_wsgi (pid=13857): Exception occurred processing WSGI script '/home/baddc0re/Desktop/htdocs/index.wsgi'.
[Thu Apr 12 19:04:38 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Apr 12 19:04:38 2012] [error] [client 127.0.0.1]   File "/home/baddc0re/Desktop/htdocs/index.wsgi", line 7, in <module>
[Thu Apr 12 19:04:38 2012] [error] [client 127.0.0.1]     from SE_controller.SE_text_parser import * #the error
[Thu Apr 12 19:04:38 2012] [error] [client 127.0.0.1] ImportError: No module named SE_controller.SE_text_parser

Graham Dumpleton

unread,
Apr 12, 2012, 7:54:50 PM4/12/12
to mod...@googlegroups.com
The permissions on /home/baddc0re are likely such that the user that
Apache runs as cannot access them.

Read:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User

and watch:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

to see what is said about permissions, especially about permissions on
home directories.

BTW:

sys.path.append('/usr/lib/python2.7/site-packages')

should not be required.

You should also perhaps learn about Python virtual environments and use them.

Graham

> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/modwsgi/-/lXc5zlfKMTkJ.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to
> modwsgi+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.

badc0re

unread,
Apr 14, 2012, 4:23:36 AM4/14/12
to mod...@googlegroups.com
I have made it with:

site.addsitedir('/home/baddc0re/Desktop/htdocs/')

Graham Dumpleton

unread,
Apr 14, 2012, 6:16:25 AM4/14/12
to mod...@googlegroups.com
If you are trying to say it works when you use that, that could only
be the case if you had .pth files in the directory
/home/baddc0re/Desktop/htdocs/. Otherwise there should be no
difference between that and doing sys.path.append() for same
directory.

Graham

On 14 April 2012 18:23, badc0re <dame.jo...@gmail.com> wrote:
> I have made it with:
>
> site.addsitedir('/home/baddc0re/Desktop/htdocs/')
>

> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/modwsgi/-/CbF0Lerej88J.

Mohd Kamal Bin Mustafa

unread,
Apr 14, 2012, 3:14:46 PM4/14/12
to mod...@googlegroups.com
On Fri, Apr 13, 2012 at 3:59 AM, badc0re <dame.jo...@gmail.com> wrote:
> the modules are working if they are in the same folder but i created the
> folder SE_controller and append the path for it but it is not working.

Does the folder SE_controller has __init__.py inside it ? That
required for python to recognize the folder as a package:-

$ ls SE_controller
__init__.py SE_text_query SE_text_parser

> Code:
>
> # -*- coding: utf-8 -*-
> import sys, os
> sys.path.append('/home/baddc0re/Desktop/htdocs') # the folder with the
> modules needer
> sys.path.append('/opt/hypertable/0.9.5.6/lib/py')
> sys.path.append('/opt/hypertable/0.9.5.6/lib/py/gen-py')
> sys.path.append('/usr/lib/python2.7/site-packages')
> from SE_controller.SE_text_parser import * #the error
> from SE_controller.SE_text_query import * #the error
> from hypertable.thriftclient import *
> from hyperthrift.gen.ttypes import *
> def application(environ, start_response):
>     status = '200 OK'
>     output = 'Hello World!>'
>     response_headers = [('Content-type', 'text/plain'),
>                         ('Content-Length', str(len(output)))]
>     start_response(status, response_headers)
>
>
>     return [output]

You can try debug this by executing the script with python and see if
you can import the module. Run this from some other directory:-

$ python /home/baddc0re/Desktop/htdocs/index.wsgi

does it run without error ? If not then definitely the import path is
wrong and not a problem with mod_wsgi. Check what sys.path contain by
placing the pdb inside the code:-

import sys, os
sys.path.append('/home/baddc0re/Desktop/htdocs') # the folder with the
modules needer
sys.path.append('/opt/hypertable/0.9.5.6/lib/py')
sys.path.append('/opt/hypertable/0.9.5.6/lib/py/gen-py')
sys.path.append('/usr/lib/python2.7/site-packages')

import pdb;pdb.set_trace()

from SE_controller.SE_text_parser import *

Now when you run it as:-

$ python /home/baddc0re/Desktop/htdocs/index.wsgi

You'll be dropped into pdb console. Print out what sys.path contains:-

pdb > sys.path

Finally, what is the output of:-

$ which python

Reply all
Reply to author
Forward
0 new messages