←back to thread

741 points chirau | 5 comments | | HN request time: 0s | source
1. andy_ppp ◴[] No.44359989[source]
I have no understanding of python really but very glad I settled on uv. It’s such an improvement user wise over poetry or pip and it’s extremely fast too.

I have one complaint though, I want ./src to be the root of my python packages such that

> from models.attention import Attention

Works if I have a directory called models with a file called attention.py in it (and __init__.py) etc. The only way this seems to work correctly is if I set PYTHONPATH=./src

Surely the environment manager could set this up for me? Am I just doing it wrong?

replies(2): >>44360056 #>>44380710 #
2. andy_ppp ◴[] No.44360056[source]
ChatGPT says two things to this “uv is a package manager not a file runner” um uv run seems to be one of the best parts of uv… and that “You’re doing things correctly you are just hitting one of Python’s most notorious pain points: managing import paths cleanly”.

I have read a few tickets saying uv won’t support this so everyone running my project will have to read the README first to get anything to run. Terrible UX.

replies(1): >>44364548 #
3. bilbo-b-baggins ◴[] No.44364548[source]
What is it that uv won’t support?
replies(1): >>44365303 #
4. andy_ppp ◴[] No.44365303{3}[source]
Setting PYTHONPATH (or for that matter any other Env vars) by default. Seems useful to me.
5. collinmanderson ◴[] No.44380710[source]
src layout _should_ work. The pyproject.toml needs to live next to src, not inside of it. You might need to `uv run python` in order to pick up the right PYTHONPATH?

https://docs.astral.sh/uv/concepts/projects/init/#packaged-a...

    uv init --package example-pkg
    cd example-pkg
    uv run python
    >>> from example_pkg import main