I am trying to run a script in Python ( v2.4 and v2.7 ) and created a module with some methods. Unfortunately this module needs to be in a separate folder.
At Python documentation and up to here in Stack Overflow I found numerous post talking to add __init__.py
to each folder in my project.
My problem is that my script stays in one structure and my module stays in another one. My situation is this:
pasta1/
script.py
pasta2/
modules/
python/
pasta3/
\__init\__.py
modulo1.py
modulo2.py
The part that I'm calling these modules in my script is:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import datetime
from pasta3.modulo1 import Mod1
from pasta3.modulo2 import Mod2
The error :
$ ./script.py
Traceback (most recent call last):
File "./script.py", line 9, in <module> from pasta3.modulo1 import Mod1
ImportError: No module named pasta3.modulo1
I can not use sys.path.append("../modules/python/")
because in Python 2.4 it is not recognized.
How to proceed in this case?