The only problem is that, despite what your question and your first comment say, you didn't add the path containing ex25.py
to your system paths.
As evidenced by the fact that, once you actually did what you claimed, everything worked fine.
For anyone with a similar problem in the future, just add this above the import
:
import sys
print(sys.path)
(If the parentheses look weird, they're just to make the same code work for both Python 2.x and 3.x.)
Now, when you run it, you'll see a list of paths. Is the path to ex25.py
in that list? If not, that's your problem. If you don't know how to fix that problem, you have something specific to ask on SO.
Note that "." (that is, the current working directory) is on sys.path
. So, running from the same directory as ex25.py
will of course fix the problem. Other things on sys.path
include:
- Your system-wide and user-specific (or, if you're using
virtualenv
, env-specific) site-packages and dist-packages directories, and anything added to that list by the site
module. This is how Python packages that you install become usable in all of your scripts.
- Note that if you just download a file and put it somewhere, rather than following its installation instructions or, e.g., using
pip
on it, it will not be installed.
- Any directories that were on the
PYTHONPATH
environment variable.
- Note that this is
PYTHONPATH
, not PATH
. Changing PATH
(or Path
) in the Windows control panel won't affect this, any more than painting all monks yellow affects monkey or chipmunks.
- Also note that changing things in the Windows control panel often does not affect any currently-open cmd.exe ("DOS prompt") windows, only future ones that you create.
- Any directories that you explicitly
append
to sys.path
in the script before calling import
.
The exact details are more complicated than this, but you really don't want to learn them—at some point you should learn how they work in Python 3.3 and later, but really, nobody wants to know how they worked in 2.7.