How Python Finds Imported Modules

The Python interpreter must locate imported modules. Where does it look for them?

When import is used within a script, the interpreter searches for the imported module in the following places sequentially:

  1. The current directory (same directory as script doing the importing).
  2. The library of standard modules.
  3. The paths defined inĀ sys.path.*

*sys.path contains a list of strings specifying the search path for modules. The list is os-dependent. To see your list, run the following code at your Python command prompt or in an IPython notebook cell:

import sys

That will output something like this:

Author: Nat Dunn

Nat Dunn is the founder of Webucator (, a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.

Follow Nat on Twitter at @natdunn and Webucator at @webucator.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.