Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Poetry and Script Entrypoints

Im trying to use Poetry and the scripts option to run a script. Like so:

pyproject.toml

[tool.poetry.scripts]
xyz = "src.cli:main"

Folder layout

   .
    ├── poetry.lock
    ├── pyproject.toml
    ├── run-book.txt
    └── src
        ├── __init__.py
        └── cli.py

I then perform an install like so:

❯ poetry install
Installing dependencies from lock file

No dependencies to install or update

If I then try and run the command its not found (?)

❯ xyz
zsh: command not found: xyz

Am i missing something here! Thanks,

like image 563
felix001 Avatar asked Feb 26 '26 08:02

felix001


1 Answers

Poetry is likely installing the script in your user local directory. On Ubuntu, for example, this is $HOME/.local/bin. If that directory isn't in your path, your shell will not find the script.

A side note: It is generally a good idea to put a subdirectory with your package name in the src directory. It's generally better to not have an __init__.py in your src directory. Also consider renaming cli.py to __main__.py. This will allow your package to be run as a script using python -m package_name.

like image 129
izzy18 Avatar answered Feb 28 '26 22:02

izzy18



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!