Search code examples
pythonpython-poetry

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,


Solution

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