←back to thread

741 points chirau | 1 comments | | HN request time: 0.325s | source
Show context
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 #
1. 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