Why can't python see my module when it's right there?
I was copying code from one installation to another and thought I had everything.
But, the code ran on one system but not the other.
I finally found the difference: an empty (all comments) file called __init.py__
That is, if in twas/brillig.py you have "from slythy.toves import gyre"
and in twas/slythy/toves.py you define the gyre class,
you need a file called __init.py__ in the twas/slythy/ directory, or you'll get an error like:
ImportError: No module named slythy.toves
Python Error: Undefined Python module brillig
There are definite disadvantages to learning python piece-by-piece as you go along. I was checking environment variables and everything before finally finding out about __init.py__
Mostly Linux & Python syntax notes and hyperlinks.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment