{
    "mode": "pydoc",
    "parameter": "py_compile",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/py_compile/json",
    "generated": "2026-06-02T13:22:05Z",
    "sections": {
        "NAME": {
            "content": "pycompile - Routine to \"compile\" a .py file to a .pyc file.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/pycompile.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module has intimate knowledge of the format of .pyc files.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.Exception(builtins.BaseException)\nPyCompileError\nenum.Enum(builtins.object)\nPycInvalidationMode\n",
            "subsections": [
                {
                    "name": "class PyCompileError",
                    "content": "|  PyCompileError(exctype, excvalue, file, msg='')\n|\n|  Exception raised when an error occurs while attempting to\n|  compile the file.\n|\n|  To raise this exception, use\n|\n|      raise PyCompileError(exctype,excvalue,file[,msg])\n|\n|  where\n|\n|      exctype:   exception type to be used in error message\n|                  type name can be accesses as class variable\n|                  'exctypename'\n|\n|      excvalue:  exception value to be used in error message\n|                  can be accesses as class variable 'excvalue'\n|\n|      file:       name of file being compiled to be used in error message\n|                  can be accesses as class variable 'file'\n|\n|      msg:        string message to be written as error message\n|                  If no value is given, a default exception message will be\n|                  given, consistent with 'standard' pycompile output.\n|                  message (or default) can be accesses as class variable\n|                  'msg'\n|\n|  Method resolution order:\n|      PyCompileError\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, exctype, excvalue, file, msg='')\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  str(self)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class PycInvalidationMode",
                    "content": "|  PycInvalidationMode(value, names=None, *, module=None, qualname=None, type=None, start=1)\n|\n|  An enumeration.\n|\n|  Method resolution order:\n|      PycInvalidationMode\n|      enum.Enum\n|      builtins.object\n|\n|  Data and other attributes defined here:\n|\n|  CHECKEDHASH = <PycInvalidationMode.CHECKEDHASH: 2>\n|\n|  TIMESTAMP = <PycInvalidationMode.TIMESTAMP: 1>\n|\n|  UNCHECKEDHASH = <PycInvalidationMode.UNCHECKEDHASH: 3>\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from enum.Enum:\n|\n|  name\n|      The name of the Enum member.\n|\n|  value\n|      The value of the Enum member.\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties inherited from enum.EnumMeta:\n|\n|  members\n|      Returns a mapping of member name->value.\n|\n|      This mapping lists all enum members, including aliases. Note that this\n|      is a read-only view of the internal mapping.\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "compile",
                    "content": "Byte-compile one Python source file to Python bytecode.\n\n:param file: The source file name.\n:param cfile: The target byte compiled file name.  When not given, this\ndefaults to the PEP 3147/PEP 488 location.\n:param dfile: Purported file name, i.e. the file name that shows up in\nerror messages.  Defaults to the source file name.\n:param doraise: Flag indicating whether or not an exception should be\nraised when a compile error is found.  If an exception occurs and this\nflag is set to False, a string indicating the nature of the exception\nwill be printed, and the function will return to the caller. If an\nexception occurs and this flag is set to True, a PyCompileError\nexception will be raised.\n:param optimize: The optimization level for the compiler.  Valid values\nare -1, 0, 1 and 2.  A value of -1 means to use the optimization\nlevel of the current interpreter, as given by -O command line options.\n:param invalidationmode:\n:param quiet: Return full output with False or 0, errors only with 1,\nand no output with 2.\n\n:return: Path to the resulting byte compiled file.\n\nNote that it isn't necessary to byte-compile Python modules for\nexecution efficiency -- Python itself byte-compiles a module when\nit is loaded, and if it can, writes out the bytecode to the\ncorresponding .pyc file.\n\nHowever, if a Python installation is shared between users, it is a\ngood idea to byte-compile all modules upon installation, since\nother users may not be able to write in the source directories,\nand thus they won't be able to write the .pyc file, and then\nthey would be byte-compiling every module each time it is loaded.\nThis can slow down program start-up considerably.\n\nSee compileall.py for a script/module that uses this module to\nbyte-compile all installed files (or all files in selected\ndirectories).\n\nDo note that FileExistsError is raised if cfile ends up pointing at a\nnon-regular file or symlink. Because the compilation uses a file renaming,\nthe resulting file would be regular and thus not the same type of file as\nit was previously.\n"
                },
                {
                    "name": "main",
                    "content": ""
                }
            ]
        },
        "DATA": {
            "content": "all = ['compile', 'main', 'PyCompileError', 'PycInvalidationMode']\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/pycompile.py\n\n",
            "subsections": []
        }
    },
    "summary": "pycompile - Routine to \"compile\" a .py file to a .pyc file.",
    "flags": [],
    "examples": [],
    "see_also": []
}