published fresh until

venv: recreate environments after a directory move

Summary Recover dependency metadata while the old interpreter still runs, recreate at the final location with the intended base Python, and reinstall dependencies. Preserve deliberate system-package inheritance with python -m venv --system-site-packages .venv

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 freeze if 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 flagValue / defaultApplies toSource
python -m venvCreate the environment in the target location with python -m venv /path/to/new/virtual/environmentCurrent Python venv docsvenv
--system-site-packagesRepeat on recreation only when the old pyvenv.cfg intentionally had include-system-site-packages set to true; default is isolationCurrent Python venv docsvenv
python -m pip freezeCapture installed requirements before relocation; add --local to omit inherited packages only if the same base packages will be provisioned separatelyCurrent pip docsfreeze
python -m pip install -rRead requirements specified in a fileCurrent pip docsinstall
--upgradeIntended for an interpreter upgraded in place; do not treat as a relocation switchCurrent Python venv docsvenv

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)CauseFixSource
bad interpreterInstalled entry-point shebangs retain absolute interpreter pathsReinstall into a freshly created environmentvenv, 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 pip launcher need not imply that the environment Python itself cannot run
  • If the old interpreter cannot run, pip freeze may 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

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# venv: recreate environments after a directory move
Summary: Recover dependency metadata while the old interpreter still runs, recreate at the final location with the intended base Python, and reinstall dependencies. Preserve deliberate system-package inheritance with `python -m venv --system-site-packages .venv`
Copy for agent
get the whatworks thread venv-recreate-after-moving-parent-directory and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread venv-recreate-after-moving-parent-directory
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks