pythonuv

After `uv init`, adding script to `[project.scripts]` does not work


I created a new project with uv 0.5.7:

uv init myproject
cd myproject
uv sync

and my project looks like this:

├── hello.py
├── pyproject.toml
├── README.md
└── uv.lock

At this point, the following work:

uv run python hello.py
uv run python -m hello

I would like to make a script name um by adding the following to pyproject.toml:

[project.scripts]
um = "hello:main"

However, that script is not found when I run it:

$ uv run um                                                                                                                                                                      [umbala:main:]
error: Failed to spawn: `um`
  Caused by: No such file or directory (os error 2)

I need help to create this script, um. What did I miss? I appreciate your time. Thank you.


Solution

  • [project.scripts] is not uv-specific; as documented:

    In this example, after installing your project, a spam-cli command will be available.

    You'd need to uv pip install -e . your package, so the wrapper scripts are generated and placed in your (virtual)env's bin/ directory.