Python - Module Search Path

Introduction

Python searches module files as follows:

  • The home directory of the program
  • PYTHONPATH directories (if set)
  • Standard library directories
  • The contents of any .pth files (if present)
  • The Lib\site path

Configuring Search Path

PYTHONPATH=c:\pycode\utilities;d:\pycode\package1 

Or you might instead create a text file called C:\Python33\pydirs.pth, which looks like this:

c:\pycode\utilities 
d:\pycode\package1 

sys.path List

To see how your Python configures the module search path on your platform, you can always inspect sys.path.

Demo

import sys 
print( sys.path )

Result

Related Topics