"from where?!? import what?!?"
summary
Shows how to find which file actually loads when imports misbehave: run python -m site to print sys.path entries, inspect module and module __spec__ to see on-disk origins, and use the CPython import-time timing/verbosity options to list implicit imports and import durations. Demonstrates when isolated mode or virtual environments with system site packages disabled remove surprising search paths, reproduces a real module shadowing bug where a local re.py breaks inspect and how the fix is verified.
AI-written summary · about
chapters (11)
- 0:00Welcome
- 1:10Import system problems
- 4:19Understanding sys.path
- 10:15Module shadowing
- 15:57Virtual environments limits
- 18:35Import time side effects
- 21:44Verbose import diagnostics
- 24:47Exotic import pitfalls
- 26:11Startup code side effects
- 27:40Deeper exploration
- 28:44Q&A
related talks
45mWhat happens when you import a module?
26mWhat happens behind execution of an `import` statement?
21mHacking the Python Import System
28mImport Deep Dive
30mImporting Without "import": Behind the Scenes of importlib
26mModules 101: how to avoid spaghetti, big balls of mud and houses of straw!
21mUnderstanding the Magic of Python Modules and Packages
27mNo time to idle about: Profiling import time in Python
