pyinstaller
https://pyinstaller.org/en/stable/installation.html
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller supports Python 3.8 and newer, and correctly bundles many major Python packages such as numpy, matplotlib, PyQt, wxPython, and others.
PyInstaller is tested against Windows, MacOS X, and Linux. However, it is not a cross-compiler; to make a Windows app you run PyInstaller on Windows, and to make a Linux app you run it on Linux, etc. x PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD but testing against them is not part of our continuous integration tests, and the development team offers no guarantee (all code for these platforms comes from external contributions) that PyInstaller will work on these platforms or that they will continue to be supported.
DEMO
https://github.com/mohammadhasananisi/compile_fastapi
FastAPI Compilation with PyInstaller
A guide to packaging FastAPI applications into standalone executables using PyInstaller.
Overview
This guide demonstrates how to compile a FastAPI application into an executable file using PyInstaller. This approach enables self-contained deployment without relying on external dependencies like web servers or containerization platforms.
Compiling with PyInstaller
Open a terminal window and navigate to the directory containing your FastAPI application's files.
Execute the following command to compile the application into an executable file:
pyinstaller -F main.py --clean
- The compilation process will create a
dist
directory containing the compiled executable file. The executable file will have a name based on your application's name and the chosen output format (e.g.,main
for a single-file executable).Running the Compiled Executable
- To run the compiled executable, simply execute the file. For instance, to run the executable named
main
, you would type the following command:./dist/mainThe compiled executable will start the FastAPI application and run it as a standalone process. You can then access the application at the specified port (8000 in the example) in your web browser.
PYINSTALLER找不到解决办法
https://stackoverflow.com/questions/45951964/pyinstaller-is-not-recognized-as-internal-or-external-command
I had to run
python -m PyInstaller script.py
for it to work.Even though the Python script directory is configured correctly in the environment variable PATH, you can observe that there is no script named PyInstaller. When you
pip install
, the module goes into[python directory]/lib/site-packages
.To run a Python module, follow the pattern
python -m [script name] [args]
.Python version: 3.10.0
中文tutorial
https://zhuanlan.zhihu.com/p/99262788
标签:executable,PyInstaller,Python,fastapi,application,run,file,pyinstaller From: https://www.cnblogs.com/lightsong/p/18685677