You can use the setuptools library to help package your application into a wheel (installable module, like from PyPi), then add the scripts argument to specify how you want to run it from the command line:
setup(
...
scripts=['bin/funniest-joke'],
...
)
When we install the package, setuptools will copy the script to our PATH and make it available for general use
You can find more information here about how to incorporate this functionality.
Answer from Xiddoc on Stack OverflowYou should add main.py to your PATH. What happens when you are running flask run is that your teminal looks up the command flask in PATH and runs the program that it is pointing to. You could see it as a kind of shortcut to the program Flask.
By adding your program to your PATH, you can tell the computer that if you type helloworld in your terminal, the terminal should run /my/path/to/helloworld.py.
I don't know what OS you are on, so here are links for most common OS on how to add a PATH variable.
Windows
Linux
Mac OSX
Edit: After you gave more explanation, setuptools is what you are looking for. Please look at this reference to see how to use it.
There's an explanation here of how to tell setuptools to add a script to the Python Scripts-folder during the pip installation. You can then make that script be for example a bat-file that calls your Python-script. In that way you achieve both that you do not need to write .py for your script to run, and that it happens automatically.