I have a python project that is like this :
py/
main.py
__init__.py
myapp/
__init__.py
my/
__init__.py
exam.py
sub/
__init__.py
index.py
and my file contains :
main.py :
from myapp.sub.index import *
cd = myc()
cd.doit()
exam.py –>
class myclass():
def hel(self):
print 'Hello world'
index.py –>
from myapp.my.exam import myclass
class myc():
def doit(self):
mycc = myclass()
mycc.hel()
I use fedora and when I use command:
python main.py
prints Hello world, but when I want to start main.py in my browser with apache and mod_python this error appears:
File "/var/www/html/py/main.py", line 1, in <module>
from myapp.sub.index import *
ImportError: No module named myapp.sub.index
Isn’t relative import work in mod_python? what is the problem and what should I do?
I looks like the
PYTHONPATHenvironment variable isn’t correctly set when executing the module under mod_python.A workaround to the problem, using the directory structure described in the question, would be to add this to
main.pyfile: