Leveraging From Vikash Balasubramanian's Answer
Thanks for your helpful answer Vikash. For those coming here needing the same and more, I wanted to add a link with an example from that link for when one needs to pass additional parameters.
The link is Uvicorn Settings.
An example, that I just tested too, would be (leveraging from Vikash's code BUT changing webapp to app):
def serve():
"""Serve the web application."""
uvicorn.run("Test1:app", port=8001, reload=True, access_log=False)
if __name__ == "__main__":
serve()
I wanted to know right away after reading Vikash's answer HOW TO control the port number in case I had to run several APIs this same way.
NOTE how the first parameter must now be a string, due to the reload=True, and that Test1.py is the name of my script, so the first parameter string is therefore "Test1:app". This is ONLY for testing before you make the exe.
FOR PyInstaller work, you do NOT want to use "Test1:app" as your first parameter, and once you are committing to make an exe, you do NOT want to use reload=True anymore. SOOooo, your code would be ...
def serve():
"""Serve the web application."""
uvicorn.run(app, port=8001) # or whatever port number you want.
if __name__ == "__main__":
serve()
And your pyinstaller command from a terminal would be ...
pyinstaller --onefile Test1.py
Otherwise, running Test1.exe will look for your Test1.py script, and then what was the point of creating an exe.