Module Loading

On "import spam", the interpreter looks for the following files:

  • spam.so, spammodule.so, spammodule.sl, or spammodule.dll (compiled extensions)
  • spam.pyo (optimized bytecode, only with -O option)
  • spam.pyc (bytecode)
  • spam.py (source)

Creation of .pyc and .pyo files

  • Created automatically by the interpreter on module import
  • Contain compiled byte-code for the module.
  • .pyo files are optimized in the sense that they do not contain debugging information.
  • Regenerated if the modification date of the matching .py file is newer.
  • For distribution, only the .pyc or .pyo files are needed (the .py file can be omitted).
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 107
July 17, 2000, beazley@cs.uchicago.edu
>>>