[Python] uv's [project.scripts] won't activate the environment in venv

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have a uv project with the structure

    [project]
    name = "trapallada"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
    "pandas>=2.2.3",
    "plotly>=6.0.1",
    <more stuff>
    ]

    [tool.uv]
    package = true


    [project.scripts]
    "trap_download_obs.py" = "trapallada.xsa.util:cl_download_observations"


    (the package = true is meant to package the code in directory trapallada, which is inside the project directory)

    When I do uv pip install -e ., the script "trap_download_obs.py" is created in .venv/bin but can't actually be run since, seemingly, the venv environment is not activated. The content of the script is

    #!/export/usuarios01/mvazquez/Sync/git/trapallada/.venv/bin/python3
    # -*- coding: utf-8 -*-
    import sys
    from trapallada.xsa.util import cl_download_observations
    if __name__ == "__main__":
    if sys.argv[0].endswith("-script.pyw"):
    sys.argv[0] = sys.argv[0][:-11]
    elif sys.argv[0].endswith(".exe"):
    sys.argv[0] = sys.argv[0][:-4]
    sys.exit(cl_download_observations())


    and the error

    File "/export/usuarios01/mvazquez/Sync/git/trapallada/.venv/bin/trap_download_obs.py", line 4, in <module>
    from trapallada.xsa.util import cl_download_observations
    ModuleNotFoundError: No module named 'trapallada'


    If I activate the environment myself, then from trapallada.xsa.util import cl_download_observations will run.

    Any clue?

    Continue reading...

Compartilhe esta Página