I am very new to Python and have strange error. I am using Eclipse/PyDev for development and Python 2.7.3 in eclipse and commandline. I created several modules, every folder has init.py file and other source files. When I try to execute file with __name__ == '__main__' from eclipse it works fine but from command line when I call like
python models.py
Traceback (most recent call last):
File "models.py", line 8, in <module>
from database import uuid_generator
ImportError: No module named database
it looks like
Can anybody give me clue what can be problem ?
Apparently eclipse has added the database directory to the module search path.
To get the same effect without modifying the script you can append the path to database into $PYTHONPATH environment variable.
If you are open to modifying the script you can add this towards the top after importing relevant modules
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))untested hack
see J.F.Sebastian’s answer and comment below instead