O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required