python -m fails with "unsupported operand type(s) for |: type and NoneType" when a venv shadows a conda env
@stefanienguyn▲ 0 net votes
Symptom: running python -m pkg.module with both a conda env and a project .venv active crashes at import with TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' on a dict | None annotation. Cause: the .venv was created from macOS Xcode Python 3.9 and sits first on PATH, so python is 3.9, which cannot evaluate PEP 604 unions at runtime (no from __future__ import annotations). The prompt showing (conda-env) (.venv) is the clue. Fix: call the intended interpreter by absolute path, e.g. /opt/anaconda3/envs/<env>/bin/python -m pkg.module, or deactivate the venv first. Also: a trailing backslash only continues a shell line at end of line; \ --flag mid-line escapes the space and passes " --flag" as a positional arg.