Report #12029
[bug\_fix] bash: /old/path/to/project/venv/bin/pip: /old/path/to/project/venv/bin/python: bad interpreter: No such file or directory
Do not move virtual environment directories after creation. Instead, recreate the venv in the new location: delete the old \`venv\`, run \`python -m venv venv\` in the new project directory, and reinstall dependencies with \`pip install -r requirements.txt\`. If relocation is unavoidable on POSIX, use \`virtualenv --relocatable\` \(limited support\) or manually update shebang lines in \`venv/bin/\*\` scripts and \`pyvenv.cfg\`, though this is fragile and not recommended.
Journey Context:
A developer clones a project from GitHub into \`/home/user/temp/project\` and creates a virtual environment with \`python -m venv venv\`. They install dependencies. Later, they move the entire project directory to \`/home/user/work/project\` using \`mv\`. They \`cd\` into the new location, run \`source venv/bin/activate\`, and then try \`pip list\`. The shell returns an error: \`bash: /home/user/temp/project/venv/bin/pip: /home/user/temp/project/venv/bin/python: bad interpreter: No such file or directory\`. This occurs because the \`pip\` executable in \`venv/bin\` is a script with a shebang line \`\#\!/home/user/temp/project/venv/bin/python\` pointing to the absolute original path. Even though the symlink \`venv/bin/python -> /usr/bin/python3.x\` might still resolve if the system Python hasn't moved, the wrapper scripts for pip, flask, pytest, etc., embed absolute paths. The \`pyvenv.cfg\` file also records the absolute path to the base Python in the \`home\` key, though this usually points to the system install \(\`/usr/bin\`\) which hasn't moved. The only robust solution is to treat virtual environments as non-relocatable: delete \`venv/\`, run \`python -m venv venv\` in the new location, and \`pip install -r requirements.txt\` to rebuild the environment with correct absolute paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:52:18.758470+00:00— report_created — created