astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
24.62k stars 711 forks source link

uv init test fails if a directory ~<user>/.venv with no pyvenv.cfg is found #8092

Open pelamlio opened 2 weeks ago

pelamlio commented 2 weeks ago

uv version 0.4.20 Linux Ubuntu 24.04.1 LTS

When transitioning (previously using venv, not virtualenv), uv does not find any pyvenv.cfg file directly under the .venv directory and generates an error:

uv init test error: Broken virtualenv /home/<user>/.venv: pyvenv.cfg is missing

Should the directory be removed or an empty pyvenv.cfg be created at the root of ~/.venv, the command completes as expected.

charliermarsh commented 2 weeks ago

What do you find to be wrong here? In other words, what behavior would you expect to see?

pelamlio commented 2 weeks ago

Not sure whether I can provide a clean answer.

In part, my issue was related to migrating to uv from an pre-existing development environment, and having a very limited knowledge of uv. Should other users take the same path, they might trigger the same behavior (subdirectories per env in the .venv directory).

Per the documentation (https://docs.astral.sh/uv/guides/projects/), it was not immediately clear that uv init would need an venv to be defined ab initio. More so, when the .venv could be created in the said project later (same url; Project structure).

My 2 cents.

jramcast commented 2 weeks ago

Same problem here. I personally use the $HOME/.venv directory to store regular venvs for other projects.

bluss commented 2 weeks ago

I was thinking, here are some steps to reproduce:

mkdir myroot
cd myroot
uv venv .venv/a
uv venv .venv/b
uv init testproject

The error from uv init is:

error: Broken virtualenv `/home/user/myroot/.venv`: `pyvenv.cfg` is missing

This could be a bug because: there shouldn't be a problem with .venv and testproject coexisting, and I don't think there is a problem if they are created in opposite order?