I have the following code structure running perfectly fine in my IDE(Aptana Studio):
/ProjectName/
/lib
/src
/Module1
/Module2
/Module3
__init__.py
pyClass.py ##Python Class
/main
main.py
main.py :
import Module3.pyClass as pc
myClass=pc.pyClass()
but when I try to run it from command line , import error !
importError: No module named Module3.pyClass
I am running from the /main directory. Is it because it doesn’t know where to find Module3 to import?How should i tell where it should look for Module3 ?
Thank you.
The
srcdirectory isn’t in the python module search path if you run it from themaindirectory. You’ll need to either run the script from thesrcdirectory (a wrapper script, or move it) or add thesrcdirectory tosys.path. This is probably what you want. Here’s how:(If you’re compiling/freezing it with py2exe/py2app/cxfreeze/whatever, you’ll need a slightly different solution due to the way it works.)