DEV Community

rndmh3ro
rndmh3ro

Posted on • Originally published at zufallsheld.de on

TIL how to ship an executable with Poetry

I wanted to build an executable python script on PyPi, so it can be run like MyPackage instead of python MyPackage.py.

Finding out how to do this with Poetry was hard. Googling for “Python [distribute|publish] executable” didn’t yield any useful results. I don’t even know how I found the correct answer anymore, but what you need are “scripts”: https://python-poetry.org/docs/pyproject#scripts

These scripts describe executables that will be installed in the user’s system:

[tool.poetry.scripts]
MyPackage = "MyPackage.MyPackage:main"

Enter fullscreen mode Exit fullscreen mode

After adding this to pyproject.toml and building the project, I can then run MyPackage!

Top comments (0)