Error importing modules with mod_python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Scott

    Error importing modules with mod_python

    I've installed mod_python, and everything seems to be working, but it
    fails when I try to import another file into the file that's actually
    producing the output. I have these lines at the top of index.py:

    from mod_python import apache
    from storylab import *

    .... and in the directory where index.py resides (/htdocs/python/), I
    have a directory called "storylab". Inside that directory is
    __init__.py. When I try to execute /htdocs/python/index.py, I get the
    following error:

    ---

    MOD_PYTHON ERROR
    ProcessId: 828
    Interpreter: 'localhost'
    ServerName: 'localhost'
    DocumentRoot: 'C:/htdocs'
    URI: '/python/index.py'
    Location: None
    Directory: 'C:/htdocs/python/'
    Filename: 'C:/htdocs/python/index.py'
    PathInfo: ''
    Phase: 'PythonHandler'
    Handler: 'index'

    Traceback (most recent call last):

    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    1537, in HandlerDispatch
    default=default _handler, arg=req, silent=hlist.si lent)

    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    1202, in _process_target
    module = import_module(m odule_name, path=path)

    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    296, in import_module
    log, import_path)

    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    680, in import_module
    execfile(file, module.__dict__ )

    File "C:\htdocs\pyth on\index.py", line 2, in <module>
    from storylab import *

    ImportError: No module named storylab

    ---

    What am I doing wrong? Any insight would be greatly appreciated.

    Thanks,
    Aaron
  • Diez B. Roggisch

    #2
    Re: Error importing modules with mod_python

    Aaron Scott wrote:
    I've installed mod_python, and everything seems to be working, but it
    fails when I try to import another file into the file that's actually
    producing the output. I have these lines at the top of index.py:
    >
    from mod_python import apache
    from storylab import *
    >
    ... and in the directory where index.py resides (/htdocs/python/), I
    have a directory called "storylab". Inside that directory is
    __init__.py. When I try to execute /htdocs/python/index.py, I get the
    following error:
    >
    ---
    >
    MOD_PYTHON ERROR
    ProcessId: 828
    Interpreter: 'localhost'
    ServerName: 'localhost'
    DocumentRoot: 'C:/htdocs'
    URI: '/python/index.py'
    Location: None
    Directory: 'C:/htdocs/python/'
    Filename: 'C:/htdocs/python/index.py'
    PathInfo: ''
    Phase: 'PythonHandler'
    Handler: 'index'
    >
    Traceback (most recent call last):
    >
    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    1537, in HandlerDispatch
    default=default _handler, arg=req, silent=hlist.si lent)
    >
    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    1202, in _process_target
    module = import_module(m odule_name, path=path)
    >
    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    296, in import_module
    log, import_path)
    >
    File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
    680, in import_module
    execfile(file, module.__dict__ )
    >
    File "C:\htdocs\pyth on\index.py", line 2, in <module>
    from storylab import *
    >
    ImportError: No module named storylab
    >
    ---
    >
    What am I doing wrong? Any insight would be greatly appreciated.
    You need to tell python that it should add the path your storylab-module is
    residing in to the sys.path-list of module locations.

    There are a bunch of ways to do so:

    - in your main-script, import sys, and append the proper path to sys.path
    - add a .pth-file into python's site-packages that points to the location
    - set the environment variable PYTHONPATH
    - use distutils or setuptools to proper install the module.

    Google will help you to find additional information about the above
    mentioned concepts.

    Diez

    Comment

    • Graham Dumpleton

      #3
      Re: Error importing modules with mod_python

      On Jul 22, 3:30 am, Aaron Scott <aaron.hildebra ...@gmail.comwr ote:
      I've installedmod_py thon, and everything seems to be working, but it
      fails when I try to import another file into the file that's actually
      producing the output. I have these lines at the top of index.py:
      >
      frommod_pythoni mport apache
      from storylab import *
      >
      ... and in the directory where index.py resides (/htdocs/python/), I
      have a directory called "storylab". Inside that directory is
      __init__.py. When I try to execute /htdocs/python/index.py, I get the
      following error:
      >
      ---
      >
      MOD_PYTHONERROR
      ProcessId:      828
      Interpreter:    'localhost'
      ServerName:     'localhost'
      DocumentRoot:   'C:/htdocs'
      URI:            '/python/index.py'
      Location:       None
      Directory:      'C:/htdocs/python/'
      Filename:       'C:/htdocs/python/index.py'
      PathInfo:       ''
      Phase:          'PythonHandler'
      Handler:        'index'
      >
      Traceback (most recent call last):
      >
        File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
      1537, in HandlerDispatch
          default=default _handler, arg=req, silent=hlist.si lent)
      >
        File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
      1202, in _process_target
          module = import_module(m odule_name, path=path)
      >
        File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
      296, in import_module
          log, import_path)
      >
        File "C:\Python25\li b\site-packages\mod_py thon\importer.p y", line
      680, in import_module
          execfile(file, module.__dict__ )
      >
        File "C:\htdocs\pyth on\index.py", line 2, in <module>
          from storylab import *
      >
      ImportError: No module named storylab
      >
      ---
      >
      What am I doing wrong? Any insight would be greatly appreciated.
      You can't put Python packages in same directory as handler scripts
      managed by mod_python. See documentation for import_module() in:



      Graham


      Comment

      Working...