importlib.import_module
Up: importlib | Next: importlib.invalidate_caches
Rel: importlib.invalidate_caches, importlib.reload
Ref: docs.python.org — importlib.import_module
Tags: #public #python3 #stdlib #importlib
Import
import importlib
from importlib import import_module
Signature & Overview
importlib.import_module(name, package=None)
Import a module.
Usage
import importlib
math_mod = importlib.import_module("math")
assert math_mod.sqrt(16) == 4.0
Gotchas
- Relative imports require
package=:importlib.import_module(".utils", package="mypkg"). - Cleanest way to load plugins or optional dependencies dynamically.
REPL Inspect
from importlib import import_module
help(import_module)
Linked from
Related notes
- tuts/python3/stdlib_module/importlib/invalidate_caches Linked here; links to this page; shared tags: #importlib, #stdlib
- tuts/python3/stdlib_module/importlib/reload Linked here; links to this page; shared tags: #importlib, #stdlib
- tuts/python3/stdlib_module/importlib Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib