imp
| Use Case | Command | Description |
|---|---|---|
| Acquire import lock | imp.acquire_lock() | Acquires the interpreter's import lock for thread safety |
| Release import lock | imp.release_lock() | Releases the lock |
| Check lock status | imp.lock_held() | Returns True if lock is held |
| Find a module | imp.find_module(name, [path]) | Search for a module DEPRECATED |
| Load a module | imp.load_module(name, file, filename, details) | Load a module found by find_module() DEPRECATED |
| Get .pyc path from .py | imp.cache_from_source(path) | Return the .pyc file path DEPRECATED |
| Get .py path from .pyc | imp.source_from_cache(path) | Return the .py file path DEPRECATED |
| Get magic number | imp.get_magic() | Return magic bytes for .pyc files DEPRECATED |
| Get suffix list | imp.get_suffixes() | Return importable module suffixes DEPRECATED |
| Check builtβin module | imp.is_builtin(name) | Returns True if module is builtβin |
| Check frozen module | imp.is_frozen(name) | Returns True if module is frozen |
| Reload a module | imp.reload(module) | Reload an already imported module DEPRECATED |
β οΈ This module is deprecated β prefer importlib for new code.
https://docs.python.org/3.10/library/imp.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
This module provides the components needed to build your own __import__ function. Undocumented functions are obsolete.
In most cases it is preferred you consider using the importlib module's functionality over this module.
builtins.object
NullImporter
DEPRECATED β Null import object.
NullImporter(path)Methods defined here:
__init__(self, path) β Initialize self. See help(type(self)) for accurate signature.find_module(self, fullname) β Always returns None.Data descriptors defined here:
__dict__ β dictionary for instance variables (if defined)__weakref__ β list of weak references to the object (if defined)acquire_lock()Acquires the interpreter's import lock for the current thread.
This lock should be used by import hooks to ensure thread-safety when importing modules. On platforms without threads, this function does nothing.
cache_from_source(path, debug_override=None)DEPRECATED
Given the path to a .py file, return the path to its .pyc file.
The .py file does not need to exist; this simply returns the path to the .pyc file calculated as if the .py file were imported.
If debug_override is not None, then it must be a boolean and is used in place of sys.flags.optimize.
If sys.implementation.cache_tag is None then NotImplementedError is raised.
create_dynamic(...)Create an extension module.
find_module(name, path=None)DEPRECATED
Search for a module.
If path is omitted or None, search for a built-in, frozen or special module and continue search in sys.path. The module name cannot contain '.'; to search for a submodule of a package, pass the submodule name and the package's __path__.
get_frozen_object(name, /)Create a code object for a frozen module.
get_magic()DEPRECATED
Return the magic number for .pyc files.
get_suffixes()DEPRECATED
get_tag()Return the magic tag for .pyc files.
init_builtin(name)DEPRECATED
Load and return a built-in module by name, or None if such module doesn't exist
init_frozen(name, /)Initializes a frozen module.
is_builtin(name, /)Returns True if the module name corresponds to a built-in module.
is_frozen(name, /)Returns True if the module name corresponds to a frozen module.
is_frozen_package(name, /)Returns True if the module name is of a frozen package.
load_compiled(name, pathname, file=None)DEPRECATED
load_dynamic(name, path, file=None)DEPRECATED
Load an extension module.
load_module(name, file, filename, details)DEPRECATED
Load a module, given information returned by find_module().
The module name must include the full package name, if any.
load_package(name, path)DEPRECATED
load_source(name, pathname, file=None)lock_held()Return True if the import lock is currently held, else False.
On platforms without threads, return False.
new_module(name)DEPRECATED
Create a new module.
The module is not entered into sys.modules.
release_lock()Release the interpreter's import lock.
On platforms without threads, this function does nothing.
reload(module)DEPRECATED
Reload the module and return it.
The module must have been successfully imported before.
source_from_cache(path)DEPRECATED
Given the path to a .pyc. file, return the path to its .py file.
The .pyc file does not need to exist; this simply returns the path to the .py file calculated to correspond to the .pyc file. If path does not conform to PEP 3147 format, ValueError will be raised. If sys.implementation.cache_tag is None then NotImplementedError is raised.
C_BUILTIN = 6C_EXTENSION = 3IMP_HOOK = 9PKG_DIRECTORY = 5PY_CODERESOURCE = 8PY_COMPILED = 2PY_FROZEN = 7PY_RESOURCE = 4PY_SOURCE = 1SEARCH_ERROR = 0/usr/lib/python3.10/imp.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 18:12 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format