Python error "ImportError: No module named"
Based on your comments to orip's post, I guess this is what happened:
- You edited
- The windows editor added something non-printing, perhaps a carriage-return (end-of-line in Windows is CR/LF; in unix it is LF only), or perhaps a CTRL-Z (windows end-of-file).
- You used WinSCP to copy the file to your unix box.
- WinSCP thought: "This has something that's not basic text; I'll put a .bin extension to indicate binary data."
- The missing
__init__.py.bin) means python doesn't understand toolkit as a package.
- You create
__init__.pyin the appropriate directory and everything works... ?
I ran into something very similar when I did this exercise in LPTHW; I could never get Python to recognise that I had files in the directory I was calling from. But I was able to get it to work in the end. What I did, and what I recommend, is to try this:
(NOTE: From your initial post, I am assuming you are using an *NIX-based machine and are running things from the command line, so this advice is tailored to that. Since I run Ubuntu, this is what I did)
1) Change directory (cd) to the directory above the directory where your files are. In this case, you're trying to run the
mountain.py file, and trying to call the
toolkit.interface.py module, which are in separate directories. In this case, you would go to the directory that contains paths to both those files (or in other words, the closest directory that the paths of both those files share). Which in this case is the
2) When you are in the
tookit directory, enter this line of code on your command line:
This sets your PYTHONPATH to ".", which basically means that your PYTHONPATH will now look for any called files within the directory you are currently in, (and more to the point, in the sub-directory branches of the directory you are in. So it doesn't just look in your current directory, but in all the directories that are in your current directory).
3) After you've set your PYTHONPATH in the step above, run your module from your current directory (the
toolkit directory). Python should now find and load the modules you specified.
Hope this helps. I was quite frustrated with this myself.