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 OverflowHow to build and run a Python command line application? - Stack Overflow
How to create a Windows command line application and its installer from wheels - Packaging - Discussions on Python.org
command line interface - How can I setup a python CLI application so that I can use it without directly referring to the interpreter? - Stack Overflow
making my program a command line application?
hey, i want to make my program i made a few weeks back into a command line application
Just to be sure, what kind of application do you think it is right now?
More on reddit.comYou 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.