koopa-python
/koopa-python
Python virtual environment lessons, why moving a project directory breaks .venv/bin/activate's hardcoded absolute path, and why direnv's PATH_add is relocation-proof where source activate is not. Use when a console-script entry point becomes "command not found" after moving a project directory, when writing or debugging a .envrc that activates a Python venv, or when deciding between PATH_add and source activate under direnv's strict_env.
- Author
- acidgenomics ↗
- Repository
- koopa ↗
- Licence
- Apache-2.0
- Last repository change
- 26.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Python virtual environment lessons, why moving a project directory breaks .venv/bin/activate's hardcoded absolute path, and why direnv's PATH_add is relocation-proof where source activate is not. Use when a console-script entry point becomes "command not found" after moving a project directory, when writing or debugging a .envrc that activates a Python venv, or when deciding between PATH_add and source activate under direnv's strict_env.
Triggers from the description
Original author description
Python virtual environment lessons, why moving a project directory breaks .venv/bin/activate's hardcoded absolute path, and why direnv's PATH_add is relocation-proof where source activate is not. Use when a console-script entry point becomes "command not found" after moving a project directory, when writing or debugging a .envrc that activates a Python venv, or when deciding between PATH_add and source activate under direnv's strict_env.
How it works
- Moving a .venv breaks activate scripts: use PATHadd in .envrc instead
SKILL.md preview
---
name: koopa-python
description: >-
Python virtual environment lessons, why moving a project directory breaks
.venv/bin/activate's hardcoded absolute path, and why direnv's PATH_add is
relocation-proof where source activate is not. Use when a console-script
entry point becomes "command not found" after moving a project directory,
when writing or debugging a .envrc that activates a Python venv, or when
deciding between PATH_add and source activate under direnv's strict_env.
---
# Python Virtual Environment Lessons
## Moving a `.venv` breaks `activate` scripts: use `PATH_add` in `.envrc` instead
**Symptom.** After moving a project directory, `mycli` (or any console-script
entry point) is `command not found` in a fresh shell, and the shell prompt shows
the wrong Python version (e.g. koopa's system Python instead of the venv's).
**Root cause.** Python `venv` `activate` scripts hardcode the absolute path of
the venv at creation time:
```bash
# .venv/bin/activate (generated by `python -m venv` or `uv venv`)
VIRTUAL_ENV='/old/absolute/path/to/.venv' # ← NEVER updated on move
```
When the project directory is moved (e.g. `~/git/foo` → `~/git/work/foo`), `uv
sync` regenerates entry-point scripts and `.pth` files at the new path, but does
**not** rewrite the `activate` scripts. If `.envrc` does `source
.venv/bin/activate`, the old (now dead) path is prepended to `PATH`. The real
`.venv/bin` never appears on `PATH` → entry points are not found.
**Fix: use direnv-native `PATH_add` instead of `source activate`.** `PATH_add`
resolves relative to `$PWD`, so it is relocation-proof by design.
```bash
# .envrc: CORRECT (relocation-proof)
if [[ -d '.venv/bin' ]]
then
export VIRTUAL_ENV="$(expand_path .venv)"
export VIRTUAL_ENV_PROMPT='.venv'
PATH_add '.venv/bin'
fi
```
```bash
# .envrc: BROKEN on directory move
if [[ -f '.venv/bin/activate' ]]
then
source '.venv/bin/activate' # hardcodes absolute path from creation time
fi
```
`expand_path .venv` is a direnv built-in that turns a relative path into an
absolute one anchored at `$PWD`, it does NOT bake in a hardcoded path.
**Note on `strict_env`.** `source .venv/bin/activate` also interacts poorly
with `strict_env = true` in `direnv.toml` (`set -euo pipefail`). `PATH_add`
is safe under strict mode.
**If you need to fix a stale venv's activate scripts** (for manual `source`
outside direnv), recreate the venv:
```bash
rm -rf .venv && uv sync --extra cli
```
Run this yourself, the agent should NOT run it (no-install rule).
Versions
The database has no other skills named koopa-python.
Database snapshot: 13.11.2026 · package version 8f1255fe7ca6 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100direnv
direnv loads and unloads environment variables automatically when you enter and leave a directory, using a per-project .envrc file. Use when a user asks to manage env vars per project, auto-switch configs, avoid manually sourcing .env files, set up .envrc, use dotenv with… - 100direnv-dotenv-environment-isolation
Use this skill when managing project-specific environment variables and isolating configuration securely with direnv. - 100python-venv-requests
Creates an isolated Python virtual environment for a project, installs a pinned version of requests in it and records the dependencies in requirements.txt. Use when the user wants to "create a venv", "isolate a Python project's dependencies", "install requests cleanly" or… - 100venv-manager
Create, manage, and validate Python virtual environments. Use for project isolation and dependency management. - 90mise-environment-management
Use when managing environment variables and project settings with Mise. Covers env configuration, direnv replacement, and per-directory settings. - 100uv-package-manager
Master the uv package manager for fast Python dependency management, virtual environments, and modern Python project workflows. Use when setting up Python projects, managing dependencies, or optimi...