pywho
One command to explain your Python environment, trace imports, and detect shadows.
Ever asked "Which Python am I running? Why did import X load that file? Do I have any files shadowing real modules? Why does this work on your machine and not on mine?" — pywho answers all of it instantly.
| Command | Description |
|---|---|
pywho |
Show a full report of your Python environment |
pywho --json |
Output environment report as JSON |
pywho --packages |
Include all installed packages in the report |
pywho --no-pip |
Skip pip version detection |
pywho trace <module> |
Trace where an import resolves and show search order |
pywho trace <module> --verbose |
Trace with full sys.path search log |
pywho trace <module> --json |
Trace output as JSON |
pywho scan . |
Scan project for files that shadow stdlib/installed packages |
pywho scan . --no-installed |
Scan against stdlib only (skip installed packages) |
pywho scan . --json |
Scan output as JSON |
pywho doctor |
Check the environment for the usual setup problems |
pywho diff a.json b.json |
Compare two environment snapshots |
pywho --python <path> ... |
Run any command inside another interpreter or virtual environment |
python -m pywho |
Run as a Python module |
pip install pywhoOr with uv:
uv add --dev pywhoFor one-off usage without installing anything into the project:
uvx pywho --python .venvNote:
uvx pywho,pipx run pywhoanduv run --with pywho pywhoall run pywho inside a separate, temporary environment, and on their own they describe that environment, not your project. Useuvxorpipx runtogether with--python. See Inspecting Another Interpreter.
- "Works on my machine" is the #1 debugging friction in Python. pywho kills it with one command.
- Paste the output into a GitHub issue, Slack message, or Stack Overflow question. Done.
- Zero dependencies. Pure stdlib. Works everywhere Python runs.
- Cross-platform. Linux, macOS, Windows. Python 3.10+.
pywho pywho - Python Environment Inspector
==============================================
Interpreter
Executable: /Users/dev/myproject/.venv/bin/python3
Version: 3.12.3 (CPython)
Compiler: Clang 15.0.0 (clang-1500.3.9.4)
Architecture: 64-bit
Build: main, Apr 9 2024, 08:09:14
Platform
System: Darwin 24.1.0
Machine: arm64
Virtual Environment
Active: Yes
Type: uv
Path: /Users/dev/myproject/.venv
Prompt: myproject
Paths
Prefix: /Users/dev/myproject/.venv
Base Prefix: /opt/homebrew/Cellar/python@3.12/...
Site-packages: /Users/dev/myproject/.venv/lib/python3.12/site-packages
Package Manager
Detected: uv
pip version: 24.0
sys.path
[0] /Users/dev/myproject/.venv/bin
[1] /opt/homebrew/.../python312.zip
[2] /opt/homebrew/.../python3.12
...
pywho --jsonpywho --packagespywho --no-pippython -m pywhoTrace exactly where an import resolves and why:
pywho trace requests Import Resolution: requests
===========================
Resolved to: /Users/dev/myproject/.venv/lib/python3.12/site-packages/requests/__init__.py
Module type: third-party (package)
Package: requests 2.32.3 (installed by uv; required by httpie)
Search order:
[0] /Users/dev/myproject -> not found
[2] /opt/homebrew/.../python3.12 -> not found
[4] /Users/dev/myproject/.venv/lib/python3.12/site-packages
-> FOUND /Users/dev/myproject/.venv/lib/python3.12/site-packages/requests/__init__.py
What the report tells you:
- Resolved to is the file a fresh program started in this folder would import. The modules pywho itself has loaded do not decide the answer.
- Package names the installed distribution that put the file there, even when the names differ (
import yamlcomes fromPyYAML), the tool that installed it, and the installed packages that require it. - Search order numbers are the real positions in
sys.path. The current folder is searched first, as it is when you run a script from it.
A dotted name such as pywho trace requests.adapters imports the parent package (requests) first, exactly as Python would. If that import fails, the error is shown instead of a crash.
pywho trace json --verbosepywho trace requests --json$ pywho trace requests
WARNING: '/Users/dev/myproject/requests.py' shadows installed package at '/Users/dev/myproject/.venv/lib/python3.12/site-packages/requests/__init__.py'Scan an entire project for files that shadow stdlib or installed packages:
$ pywho scan .
Found 2 shadow(s)
2 HIGH (stdlib)
[HIGH] json.py
shadows stdlib module 'json'
[HIGH] math.py
shadows stdlib module 'math'pywho scan . --jsonpywho scan . --no-installedSmart exclusions — these directories are automatically skipped: .venv, __pycache__, node_modules, dist, build, .git, and more.
"Installed" means importable from a site-packages folder. A project file never counts as shadowing itself, so the result is the same whether you run pywho scan ., python -m pywho scan ., or have the project installed in editable mode.
pywho doctor looks for the usual reasons an environment misbehaves and tells you which one applies:
$ pywho doctor
pywho doctor
============
[ OK ] The activated virtual environment is in use.
[FAIL] pip and python on PATH belong to different environments.
python -> /Users/dev/myproject/.venv/bin/python (Python 3.12)
pip -> /opt/homebrew/bin/pip (Python 3.11)
pip installs into -> /opt/homebrew/lib/python3.11/site-packages
[WARN] Environment variables change where every Python looks for modules.
PYTHONPATH=/Users/dev/old-libs
[ OK ] Every sys.path entry exists.
[ OK ] No duplicate or broken packages.
[ OK ] No .pth file points to a missing folder.
1 problem, 1 warning| Check | What it catches |
|---|---|
| Activated environment | VIRTUAL_ENV points to one environment while another Python is running |
python and pip on PATH |
pip install puts packages where python never looks |
| Environment variables | PYTHONPATH or PYTHONHOME silently changing every Python |
sys.path |
Entries that do not exist |
| Packages | The same package installed in two versions, or a folder left without metadata by a failed uninstall |
.pth files |
Files pointing to a folder that is gone (a moved editable install) |
| Externally managed | A system Python that refuses pip install (PEP 668) |
Exit code is 1 when a check fails, 0 otherwise. Warnings are advice and do not change the exit code. Use pywho doctor --json in scripts.
Save a snapshot on each machine, then let pywho show what differs:
# On each machine
pywho --json --packages > env.json
# Anywhere
pywho diff mine.json theirs.json pywho diff
==========
A: mine.json
B: theirs.json
Environment
interpreter.version: 3.12.3 -> 3.11.9
platform.system: Darwin -> Linux
Packages
Only in A (1)
idna 3.7
Different version (1)
requests 2.31.0 -> 2.32.3
Folder paths are left out of the comparison: they differ on every machine and would hide what matters. Exit code is 1 when the snapshots differ, 0 when they match. Snapshots made without --packages are compared without their package lists.
Every command accepts --python. pywho then runs inside that interpreter, which does not need pywho installed:
pywho --python .venv # a virtual environment folder
pywho --python /usr/bin/python3.11 # an interpreter
pywho --python python3 doctor # a command on PATH
pywho --python ../other-project/.venv trace requestsThis is what makes a single global install useful for every project:
uvx pywho --python .venv
pipx run pywho --python .venv doctorThe target must be Python 3.10 or newer. Nothing from pywho's own environment leaks into the report.
from pywho import inspect_environment
report = inspect_environment()
print(report.executable) # /usr/bin/python3
print(report.venv.is_active) # True
print(report.venv.type) # "uv"
print(report.package_manager) # "uv"
# Get JSON-serializable dict
data = report.to_dict()from pywho import trace_import
trace = trace_import("requests")
print(trace.resolved_path) # /path/to/requests/__init__.py
print(trace.module_type) # ModuleType.THIRD_PARTY
print(trace.provided_by) # [ProvidingPackage(name='requests', version='2.32.3', ...)]
print(trace.shadows) # [] (empty = no shadows)
if trace.shadows:
for s in trace.shadows:
print(f"WARNING: {s.description}")from pywho import scan_path
from pathlib import Path
results = scan_path(Path("."))
for r in results:
print(f"[{r.severity.value.upper()}] {r.path} shadows {r.module_name}")from pywho import run_doctor
for check in run_doctor():
print(check.status.value, check.summary)from pywho import diff_reports, inspect_environment
from pywho.differ import load_snapshot
diff = diff_reports(inspect_environment().to_dict(), load_snapshot("theirs.json"))
for package in diff.packages:
print(package.name, package.a, "->", package.b)- CPython, PyPy, and other implementations
- Version, compiler, architecture (32/64-bit)
- Build date
| Type | Detection method |
|---|---|
| venv | sys.prefix != sys.base_prefix |
| virtualenv | virtualenv = in pyvenv.cfg |
| uv | uv = in pyvenv.cfg |
| conda | conda-meta folder in sys.prefix |
| poetry | POETRY_ACTIVE env var, inside a virtual environment |
| pipenv | PIPENV_ACTIVE env var, inside a virtual environment |
A virtual environment created on top of conda is reported as the virtual environment it is, not as conda.
Detects: pip, uv, conda, poetry, pipenv, pyenv
sys.prefix,sys.base_prefix,sys.exec_prefix- All
site-packagesdirectories - Full
sys.pathwith index numbers
With --packages: lists all installed packages with versions and locations.
- Single-module detection via
pywho trace - Project-wide scanning via
pywho scan - Severity levels: HIGH (stdlib) and MEDIUM (installed)
- Activated environment that is not the running Python
pipandpythonfrom different environmentsPYTHONPATH/PYTHONHOMEoverrides- Packages installed in two versions and broken package folders
- Stale
.pthfiles and missingsys.pathentries
| Scenario | Command |
|---|---|
| Debug "works on my machine" | pywho --json --packages > env.json, then pywho diff mine.json theirs.json |
| Verify onboarding setup | pywho doctor |
| CI environment snapshots | pywho --json --packages > env.json |
| Fail CI on a broken environment | pywho doctor (exit code 1 on a problem) |
| Find why an import is wrong | pywho trace <module> |
| Find which package provides a module | pywho trace <module> |
| Audit project for shadows | pywho scan . |
| Inspect a project from a global install | pywho --python .venv |
| Ask users for their env | "Please run pywho" |
| Platform | Status |
|---|---|
| Linux | ✅ Supported |
| macOS | ✅ Supported |
| Windows | ✅ Supported |
| Python | Status |
|---|---|
| 3.10+ | ✅ Supported |
| 3.10 – 3.15 | ✅ Tested in CI |
git clone https://github.com/AhsanSheraz/pywho.git
cd pywho
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"
pytest -v
mypy src/pywho