The Module Search Path

When loading modules, the interpreter searches the list of directories in sys.path. The following is a typical value of sys.path:

['',  '/usr/local/lib/python2.0',
      '/usr/local/lib/python2.0/plat-sunos5',
      '/usr/local/lib/python2.0/lib-tk',
      '/usr/local/lib/python2.0/lib-dynload',
      '/usr/local/lib/python2.0/site-packages']

The empty string '’ refers to the current directory.

To add new directories to the search path, simply append them to this list.

In addition to directories, ZIP archive files containing Python modules can be added to the search path. This can be a convenient way to package a collection of modules as a single file. For example, suppose you created two modules, foo.py and bar.py, and placed them in a zip file ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.