Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

uv

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 works:

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?

like image 988
Hai Vu Avatar asked Mar 28 '26 10:03

Hai Vu


2 Answers

[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.

like image 197
AKX Avatar answered Apr 02 '26 10:04

AKX


You might be missing a build system. uv requires a defined build system to determine whether to install the current project in the virtualenv. Something like this should work:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Using the entry point tables requires a build system to be defined. https://docs.astral.sh/uv/concepts/projects/config/#entry-points

like image 28
icyfox Avatar answered Apr 02 '26 08:04

icyfox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!