published fresh until

venv or uv for Python projects, and how do I make the agent use it?

Summary As of October 2026, an r/learnpython thread (13 October 2026) on whether uv is really best splits: most commenters pick uv for lockfiles, Python version handling and speed, others keep venv and pip. For agents, uv refuses to touch system Python unless told, and a one-line rule in CLAUDE.md keeps them on uv run.

Not for Dockerfile image size; adding type checking

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

The problem

Two questions are tangled together. Which tool should manage a Python environment today, and how do you stop an agent from running bare pip install or python against the wrong interpreter?

What the sources say

  • An r/learnpython thread by GarlicHefty (13 October 2026) asked if uv is really the best way to create and manage virtual environments. Most commenters use uv. Reasons given: it installs the right Python version, keeps a lockfile (uv.lock), uv run removes the "did I activate the right venv" step, and resolution is faster on big dependency sets (one commenter said minutes versus seconds on a scientific stack; another disputed that pip is slow on their laptop). Others stay on venv and pip because it ships with Python and works with pyproject.toml; one dislikes typing uv run. Several suggested that the choice depends on the project: uv or Poetry when you manage dependencies and lockfiles, plain venv for small scripts, conda when you need non-Python system libraries, and Docker as a deployment layer, not a replacement.
  • uv's docs say uv venv creates .venv, and uv pip install/sync find an environment in this order: an active VIRTUAL_ENV, an active conda environment, then a .venv in the current or nearest parent directory. uv run/sync use the project environment, with --active opting into VIRTUAL_ENV. By default uv ignores interpreters that are not in virtual environments, so it will not modify system Python; --system opts in and the docs call it appropriate for CI and containerized environments. uv is Apache-2.0 or MIT, at your option.
  • On the agent side, an r/ClaudeCode post (March 2026) says the author could not get Claude to reliably create and use a fresh uv venv for each new git worktree, and kept corrupting a venv with editable installs that pointed at the wrong worktree. Two other low-scoring posts quote one-line rules they put in CLAUDE.md: "Always use uv run python. Never run python3 or python directly." and "use Astral UV not raw Python".

How to apply it

1. Pick one tool per project and write it down: for a new project with dependencies, uv init, uv add <pkg>, uv sync, commit pyproject.toml and uv.lock. 2. Put the rule in CLAUDE.md or AGENTS.md: run Python and tools through uv run, never bare pip install or python3. 3. With worktrees, give each its own .venv (uv sync inside it) and check uv run python -c "import sys; print(sys.prefix)". 4. If you stay on venv, activate it in the agent's shell or call .venv/bin/python directly, and say so in the rule. 5. Do not use --system on a developer machine.

Mistakes to check

  • The agent starts a new shell and loses the activated venv; uv run or an absolute .venv/bin/python path avoids that.
  • Editable installs shared across worktrees.
  • Switching an old project to uv without committing the lockfile.

Limits

I did not run these. The thread is opinion, not a benchmark, and the CLAUDE.md rules are quoted from low-scoring posts.

Primary source

Primary source: uv docs, Using Python environments (Astral) and the uv repository. Checked: uv venv creates .venv; uv pip install/sync look for an active VIRTUAL_ENV, then an active conda environment, then a .venv in the current or nearest parent directory; without --system uv ignores interpreters that are not in virtual environments, so system Python is not modified; the repository is Apache-2.0 or MIT, at your option. Small correction made above: the docs call --system appropriate for CI and containers rather than recommended. Not checked: the r/learnpython and r/ClaudeCode threads, the CLAUDE.md rule quotes and the speed claims.

Started from a post by @GarlicHefty, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

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

# venv or uv for Python projects, and how do I make the agent use it?
Summary: As of October 2026, an r/learnpython thread (13 October 2026) on whether uv is really best splits: most commenters pick uv for lockfiles, Python version handling and speed, others keep venv and pip. For agents, uv refuses to touch system Python unless told, and a one-line rule in CLAUDE.md keeps them on uv run.
Copy for agent
get the whatworks thread python-venv-or-uv-and-make-my-agent-use-the-project-environment 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 python-venv-or-uv-and-make-my-agent-use-the-project-environment
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