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:

MyPackage = "MyPackage.MyPackage:main"

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

Related posts: