Trying to use "Programming Python" (Lutz), getting module errors.

Steve Holden sholden at holdenweb.com
Mon May 6 08:33:34 EDT 2002


"Tiberius Teng" <tiberius at ms28.hinet.net> wrote in message
news:6c92a8bc.0205060225.46b1c6c9 at posting.google.com...
> robline at purdue.edu (Rob Lineberger) wrote in message
news:<84773476.0205052134.8c1d533 at posting.google.com>...
> > I'm trying to learn Python, so I picked up Mark Lutz' Programming
> > Python.  Using latest builds of Python and Pythonwin.
> >
> > print 'Hello world!' worked ok.
> >
> > As soon as I move on to page 13, Running Module Files, it breaks.  I
> > opened up notepad and created a file called spam.py.  When I try to
> > use it, pythonwin says no such module exists.  I saved it in My
> > Documents, but I have no idea how to tell Python to look there.  So I
> > saved it to C:\Python22\Lib\spam.py.  No dice.
> >
> > Tried using spam.py from the command prompt, IDLE, etc, all to no
> > avail.
> >
> > Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work
> > either.
> >
> > I can't learn this language if I can't create and import modules.  Any
> > advice?
>
> I would recommand you start learning Python by reading "Learning
> Python" (also by Mark Lutz & David Ascher), not "Programming Python"
> ... :)
>
> However if you put your spam.py in C:\Python22\Lib then typing 'import
> spam' inside Pythonwin / IDLE should work ...

More generally, a module will be found if it lives in a directory listed in
the sys.path list. You can modify your site globally in a number of ways.
One involves setting the PYTHONPATH environment variable, another involves
writing a site-specific <python>/Lib/sitecustomize.py, which will (if it
exists) be imported by site.py as a part of the interpreter's
initialization.

regards
 Steve
--
Steve Holden: http://www.holdenweb.com/ ; Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list