Skip to main content

使用uv和pyinstaller自动打包Python应用的工具

Project description

uvinstaller

🚀 uvinstaller 是一个自动化Python应用打包工具,使用 uvpyinstaller 将Python脚本打包成单个可执行文件。

✨ 特性

  • 🔧 自动安装uv: 如果系统中没有uv,会自动下载安装
  • 📦 智能依赖分析: 自动分析Python文件的所有依赖关系
  • 🌏 虚拟环境隔离: 使用uv创建干净的虚拟环境进行打包
  • 📱 单文件输出: 生成单个可执行文件,便于分发
  • 🧹 自动清理: 打包完成后自动清理临时文件
  • 🖥️ 跨平台支持: 支持Windows、Linux、macOS

🚀 快速开始

安装

pip install uvinstaller

使用

uvi your_script.py

就是这么简单!工具会自动:

  1. 检查并安装uv环境
  2. 分析脚本的所有依赖
  3. 创建虚拟环境并安装依赖
  4. 使用pyinstaller打包
  5. 将可执行文件复制到源码目录

📋 使用示例

基本用法

# 打包单个Python文件
uvi app.py

# 打包带路径的文件
uvi src/main.py

支持的文件结构

my_project/
├── main.py          # 主入口文件
├── utils.py         # 本地模块
├── config/          # 本地包
│   └── __init__.py
└── requirements.txt # 依赖文件(可选)

运行 uvi main.py 会自动:

  • 分析 main.py 的导入
  • 扫描同目录下的所有Python文件
  • 读取 requirements.txt(如果存在)
  • 安装所有必要的依赖

🔧 工作原理

  1. 环境检查: 检查系统是否有uv,没有则自动安装
  2. 依赖分析: 使用AST分析Python文件的导入语句
  3. 环境创建: 使用uv创建临时虚拟环境
  4. 依赖安装: 在虚拟环境中安装pyinstaller和项目依赖
  5. 文件复制: 复制源码到临时目录
  6. 执行打包: 使用pyinstaller生成单文件可执行程序
  7. 文件复制: 将可执行文件复制到源码目录
  8. 清理临时文件: 删除所有临时文件和目录

🎯 适用场景

  • 🖥️ 桌面应用: 将Python GUI应用打包为exe
  • 🔧 命令行工具: 将脚本打包为可执行工具
  • 📊 数据处理脚本: 打包数据分析脚本
  • 🌐 自动化脚本: 打包运维和自动化脚本
  • 🎮 游戏和娱乐: 打包Python游戏

📁 项目结构

uvinstaller/
├── src/
│   └── uvinstaller/
│       ├── __init__.py
│       ├── cli.py              # 命令行接口
│       ├── uv_installer.py     # uv自动安装
│       ├── dependency_analyzer.py  # 依赖分析
│       └── packager.py         # 打包器
├── pyproject.toml              # 项目配置
├── build_and_publish.py        # 构建发布脚本
└── README.md

🛠️ 开发

本地开发环境

# 克隆代码
git clone https://github.com/uvinstaller/uvinstaller.git
cd uvinstaller

# 安装开发依赖
uv pip install -e ".[dev]"

# 运行测试
pytest

构建和发布

使用提供的构建脚本:

python build_and_publish.py

脚本会自动:

  • 清理构建目录
  • 安装构建依赖
  • 构建wheel和源码包
  • 检查包的完整性
  • 可选上传到PyPI

🤝 贡献

欢迎提交Issue和Pull Request!

  1. Fork项目
  2. 创建特性分支
  3. 提交更改
  4. 推送到分支
  5. 创建Pull Request

📄 许可证

MIT License - 详见 LICENSE 文件

🙏 致谢

  • uv - 快速Python包管理器
  • PyInstaller - Python应用打包工具

📞 支持

如果遇到问题或有建议,请:

  1. 查看 Issues
  2. 创建新的Issue
  3. 联系维护者

⭐ 如果这个项目对你有帮助,请给我们一个星标!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uvinstaller-1.0.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uvinstaller-1.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file uvinstaller-1.0.0.tar.gz.

File metadata

  • Download URL: uvinstaller-1.0.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for uvinstaller-1.0.0.tar.gz
Algorithm Hash digest
SHA256 db8587d725ac576fed1178768d7261088945f6cc0cbc3a3fd5a1aa87c68bd042
MD5 7aaeb68d115f967406dfbc48400c70d9
BLAKE2b-256 d873528925232f7c84c433a25c4da228404e0fe4d5a81879cc43b33873222d08

See more details on using hashes here.

File details

Details for the file uvinstaller-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: uvinstaller-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for uvinstaller-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdccd478c44dcfdab5522f6ce82fe287cb004ae030c704d4d51a51d5630d3d8f
MD5 268942f22280a19086b078e834dac3c6
BLAKE2b-256 8a7d25143c927790f10b5ed366edb36e4cbe7fa23ab562d558beb608899a93f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page