Python error "ImportError: No module named"
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping
--
Chapters
00:00 Python Error &Quot;Importerror: No Module Named&Quot;
01:04 Answer 1 Score 97
01:24 Accepted Answer Score 326
02:23 Answer 3 Score 47
02:46 Answer 4 Score 114
04:15 Thank you
--
Full question
https://stackoverflow.com/questions/3387...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #importerror #pythonimport
#avk47
ACCEPTED ANSWER
Score 326
Based on your comments to orip's post, I guess this is what happened:
- You edited 
__init__.pyon windows. - 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(now called__init__.py.bin) means python doesn't understand toolkit as a package. - You create 
__init__.pyin the appropriate directory and everything works... ? 
ANSWER 2
Score 114
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)
Change directory (cd) to the directory above the directory where your files are. In this case, you're trying to run the
mountain.pyfile, and trying to call thetoolkit.interface.pymodule, 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 thetoolkitdirectory.When you are in the
toolkitdirectory, enter this line of code on your command line:export PYTHONPATH=.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).
After you've set your PYTHONPATH in the step above, run your module from your current directory (the
toolkitdirectory). Python should now find and load the modules you specified.
ANSWER 3
Score 97
Does
(local directory)/site-packages/toolkit
have a __init__.py?
To make import walk through your directories every directory must have a __init__.py file.
ANSWER 4
Score 47
On *nix, also make sure that PYTHONPATH is configured correctly, especially that it has this format:
 .:/usr/local/lib/python
(Mind the .: at the beginning, so that it can search on the current directory, too.)
It may also be in other locations, depending on the version:
 .:/usr/lib/python
 .:/usr/lib/python2.6
 .:/usr/lib/python2.7 and etc.