What this thread does
Do first: use the old environment's Python to run python -m pip freeze before moving it, then recreate with the intended base interpreter at the final location.
Short answer
bad interpreter after a move points to an interpreter path worth inspecting. As of November 2026, current Python docs describe venvs as non-portable because installed scripts embed absolute interpreter paths. Moving the parent directory is enough to break those paths. Recreate rather than repairing only shebangs (venv). The relocation question concerns virtualenv; it is historical context, not authority for standard-library venv behavior.
Choose / don't choose
- Recreate: choose after a directory move. Recreate the environment in the target location. (venv).
- Recover a snapshot: choose
pip freezeif the old interpreter still runs and no maintained dependency file exists; the result is not a lockfile or solver result (pip freeze). - Shebang patching: don't use as a general relocation method; Python's documented remedy is recreation. pyvenv.cfg has a home key pointing to the base Python installation (venv, PEP 405).
Not for: an editor launching the wrong interpreter in an intact environment; see python-modulenotfounderror-but-pip-installed-which-python-is-running.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
python -m venv | Create the environment in the target location with python -m venv /path/to/new/virtual/environment | Current Python venv docs | venv |
--system-site-packages | Repeat on recreation only when the old pyvenv.cfg intentionally had include-system-site-packages set to true; default is isolation | Current Python venv docs | venv |
python -m pip freeze | Capture installed requirements before relocation; add --local to omit inherited packages only if the same base packages will be provisioned separately | Current pip docs | freeze |
python -m pip install -r | Read requirements specified in a file | Current pip docs | install |
--upgrade | Intended for an interpreter upgraded in place; do not treat as a relocation switch | Current Python venv docs | venv |
Order of operations
1. Prefer the project's maintained dependency/lock input. If only installed metadata remains and the old environment Python runs, call its interpreter directly for -m pip freeze > requirements.txt (freeze, venv). 2. Record which base interpreter and inheritance policy were used. pyvenv.cfg identifies the base via home; inspect installed scripts’ shebang lines after a move (PEP 405, venv). 3. Retain the recoverable old directory until inputs are secured. At the final project location, use a fresh environment directory and the intended base Python: python -m venv /path/to/new/virtual/environment; add the inheritance flag only when intentional (venv). 4. Use python -m pip install -r requirements.txt on Unix/macOS or py -m pip install -r requirements.txt on Windows. Repoint editor/task references, inspect sys.prefix versus sys.base_prefix, and exercise the actual console entry points before retiring the old environment (venv, install).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
bad interpreter | Installed entry-point shebangs retain absolute interpreter paths | Reinstall into a freshly created environment | venv, original author's relocation report |
Missing
- The linked source does not confirm: A snapshot does not capture the base Python installation, system packages, native libraries or platform compatibility (repeatable installs).
- The linked source does not confirm: A broken bare
piplauncher need not imply that the environment Python itself cannot run - If the old interpreter cannot run,
pip freezemay be unavailable; recover the maintained dependency specification or metadata instead of promising exact reconstruction.
Checked
2026-11-12; current Python venv docs, PEP 405, pip freeze/install/repeatability references and original dated relocation question read. No environment moved, recreated or installed.
Started from a post by @Python docs and Stack Overflow questions, packaged by the editor. Original post