首页 > 其他分享 >pyinstaller package fastapi application

pyinstaller package fastapi application

时间:2025-01-22 13:59:15浏览次数:1  
标签:executable PyInstaller Python fastapi application run file pyinstaller

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

  1. Open a terminal window and navigate to the directory containing your FastAPI application's files.

  2. Execute the following command to compile the application into an executable file:

pyinstaller -F main.py --clean
 
  1. 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

  1. To run the compiled executable, simply execute the file. For instance, to run the executable named main, you would type the following command:
./dist/main
 

The 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

相关文章

  • 深度学习目标检测框架训练使用YOLOv8训练钓鱼检测数据集 使用Flask或FastAPI等框架创
    深度学习目标检测框架训练使用YOLOv8训练钓鱼检测数据集并构建一个基于YOLOv8的钓鱼检测系统使用YOLOv8训练钓鱼检测数据集,如何针对钓鱼检测进行调整和实现的详细步骤。1.安装依赖确保安装了必要的库。对于钓鱼检测,所需的库应该与之前提供的相同,但请根据实际情况检查是......
  • [超表面论文快讯-34] Light: Science & Applications-电磁超材料强化学习智能体-北京
    栏目介绍:“论文快讯”栏目旨在精简地分享一周内发表在高水平期刊上的Metasurface领域研究成果,帮助读者及时了解领域前沿动态,如果对专栏的写法或内容有什么建议欢迎留言,后续会陆续开启其他专栏,敬请期待。论文基本信息标题:Electromagneticmetamaterialagent作者:......
  • Django和FastAPI的比较
    在Python的Web开发领域,Django和FastAPI是两款备受瞩目的框架。通过对二者的实践与比较,本文总结了它们的特点与适用场景,希望能给开发者在选择时提供参考。1.设计理念的比较从框架的特性来看,Django以全栈式框架著称,内置诸多工具,涵盖ORM、数据验证、认证、会话管理、缓......
  • FastAPI 依赖注入之类依赖:使用类声明依赖项并简化查询参数
    FastAPI依赖注入之类依赖:使用类声明依赖项并简化查询参数在FastAPI中,依赖注入(DI)不仅支持函数,还支持类作为依赖项,这使得代码更加模块化与易于维护。通过类依赖,开发者能够封装复杂的业务逻辑与参数验证,提高代码的可复用性与可读性。本文介绍了如何使用类来声明依赖项并应......
  • SpringCloud+Vue+Python人工智能(fastAPI,机器学习,深度学习)前后端架构各功能实现思路
    随着公司业务的增加,公司需要一个java+python人工智能相互配合架构,正常网站业务用java来做,而ai,例如电价预测等回归任务,以及大模型预测全网负荷,新能源出力等任务,使用python通过fastapi暴露接口来做,那么就需要springcloud架构注册发现。前端统一使用Vue进行效果的展示因此本......
  • iOS 逆向学习 - iOS Application Structure:iOS 应用程序结构
    iOS逆向学习-iOSApplicationStructure:iOS应用程序结构1.什么是IPA文件?IPA的核心组成2.目录详细解析(1)App图标-`AppIcon60x60@2x.png`(2)资源文件-`Assets.car`(3)本地化资源-`Base.lproj`(4)核心文件-`GothamTimes`(可执行文件)(5)配置文件-`Info.plist`(6)签......
  • FastApi框架异步调用同步问题
    Fastapi项目,在接口中调用同步方法,如果该同步方法,耗时较长(比如连接redis超时),会造成整个项目接口的阻塞,这是任何接口的访问都会被阻塞超时一、为什么会阻塞FastAPI是基于异步框架(如asyncio或anyio)构建的,它的核心是一个事件循环(EventLoop)。事件循环负责调度和执行所有的异步......
  • Spring Cloud - bootstrap.yml vs application.yml
    WhenusingSpringCloud,the'real'configurationdataisusuallyloadedfromaserver.InordertogettheURL(andotherconnectionconfiguration,suchaspasswords,etc.),youneedanearlieror"bootstrap"configuration.Thus,you......
  • FastAPI使用异步 ORM 进行高效数据库操作与管理
    FastAPI使用异步ORM进行高效数据库操作与管理目录......
  • FastAPI 依赖注入、异步任务与分布式调度
    FastAPI依赖注入、异步任务与分布式调度目录......