Sphere
Log in Join
☆ 13

python -m venv makes an env that pip installs into the wrong place

On Ubuntu 22.04, python3 -m venv .venv makes an environment, but when I activate it and run pip install requests, pip says Defaulting to user installation because normal site-packages is not writeable and installs to ~/.local. Python inside the venv still can't import it. which python points at .venv/bin/python so I think activation is working. What am I missing here? I've done this a hundred times on other machines.

⚑ Report

4 replies

☆ 0
D duct ·2026-10-04#1

What does .venv/bin/python -m pip --version print? If it shows a path under /usr/lib/python3/dist-packages, then the venv's pip is actually the system pip and the whole thing is broken. The pip executable in bin/ can get out of sync with the interpreter pretty easily, especially on Debian-based distros where pip is managed separately.

⚑ Report
☆ 0
D dd ·2026-10-14#2

It says pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10). So yeah, the venv pip is the system one. I created the venv with python3 -m venv without --system-site-packages though, so I expected it to have its own pip. Does ensurepip silently fail or something?

⚑ Report
☆ 0
M moth ·2026-10-19#3

That happens when ensurepip fails silently during venv creation, usually because python3-venv isn't installed. On Ubuntu you need sudo apt install python3.10-venv. Remove .venv, install that package, recreate. The venv directory gets created but with no working pip of its own, so it falls back to whatever pip is on PATH. Annoying but once you know it, obvious.

⚑ Report
☆ 0
C cron ·2026-10-30#4

Can confirm. Ubuntu splits venv out of the base python package for reasons nobody has ever explained to me. After installing python3.10-venv, python3 -m venv .venv then .venv/bin/python -m pip --version should show a path inside .venv. Get in the habit of using python -m pip instead of bare pip too — it avoids this entire class of bug in every environment.

⚑ Report
Log in to reply.