How can I import my own modules on webserver?
Question: I am developing a website and want to put some files on the server. The
problem is that I can only import python modules ( e.g. "import os"), but
somewhy, can not import my own modules:

test1.py:

    
    
    import test2
    

test2.py:

    
    
    print ("Content-type:text/html\n\n")
    print ("<html>")
    print ("<head>")
    print ("<title>Error</title>")
    print ("</head>")
    print ("<body>")
    print (" hello world 2")
    print ("</body>")
    print ("</html>")
    

If I click www.mywebsite.com/test2.py, then I recieve "hello world" on the
screen. However, if I click www.mywebsite.com/test1.py, I get "500 internal
server error." I found out that it is some problem with not being able to
import my modules.

p.s. since I am on a shared server, I can not changes sys path etc....

Here is a trace I got in errors.log:

    
    
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] mod_python (pid=17816, interpreter='delekulator.co.il', phase='PythonHandler', handler='mod_python.cgihandler'): Application error
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] ServerName: 'delekulator.co.il'
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] DocumentRoot: '/var/www/vhosts/mywebsite.com/httpdocs'
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] URI: '/test1.py'
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Location: None
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Directory: '/var/www/vhosts/mywebsite.com/httpdocs/'
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Filename: '/var/www/vhosts/mywebsite.com/httpdocs/test1.py'
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] PathInfo: ''
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Traceback (most recent call last):
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249]   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249]   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target\n    result = _execute_target(config, req, object, arg)
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249]   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target\n    result = object(arg)
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249]   File "/usr/lib/python2.6/dist-packages/mod_python/cgihandler.py", line 96, in handler\n    imp.load_module(module_name, fd, path, desc)
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249]   File "/var/www/vhosts/mywebsite.com/httpdocs/test1.py", line 1, in <module>\n    import test2
    [Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] ImportError: No module named test2
    

**In the last line, you can see that the server writes "ImportError: No module
named test2"**

How can I fix it?


Answer: Modules should be in the Python path or in the same directory where the
executable is.

Then you do like usually

    
    
    import test2
    
    test2.some_function() # or whatever.
    

