92 lines
2.9 KiB
Plaintext
92 lines
2.9 KiB
Plaintext
文档搜索工具:支持搜索文档里的内容。支持搜索word,excel,PDF,zip,rar,z-zip,txt,php,js,html文件类型。
|
||
需要安装支持库:
|
||
tkinter - 通常 Python 自带,无需额外安装(如果是特殊环境缺少缺失,可根据系统安装对应包)
|
||
## PyPDF2 - 用于处理 PDF 文件
|
||
bash
|
||
pip install PyPDF2
|
||
|
||
## python-docx - 用于处理 Word 文档(.docx)
|
||
bash
|
||
pip install python-docx
|
||
|
||
## pandas - 用于处理 Excel 文件
|
||
bash
|
||
pip install pandas
|
||
|
||
|
||
## xlrd - pandas 读取 .xls 格式 Excel 文件需要
|
||
bash
|
||
pip install xlrd==1.2.0 # 注意:需要指定旧版本,新版本不支持xls
|
||
|
||
|
||
## openpyxl - pandas 读取 .xlsx 格式 Excel 文件需要
|
||
bash
|
||
pip install openpyxl
|
||
|
||
|
||
## py7zr - 用于处理 7-Zip 压缩包
|
||
bash
|
||
pip install py7zr
|
||
|
||
|
||
## rarfile - 用于处理 RAR 压缩包
|
||
bash
|
||
pip install rarfile
|
||
|
||
|
||
## 你可以将这些命令合并成一条安装命令,一次性安装所有依赖:
|
||
bash
|
||
pip install PyPDF2 python-docx pandas xlrd==1.2.0 openpyxl py7zr rarfile
|
||
|
||
|
||
# 1. 安装 PyInstaller
|
||
首先确保已安装 PyInstaller:
|
||
bash
|
||
pip install pyinstaller
|
||
# 2. 基本打包命令
|
||
在命令行中进入你的 Python 脚本所在目录,执行以下命令:
|
||
生成单个可执行文件(推荐)
|
||
bash
|
||
pyinstaller --onefile your_script.py
|
||
--onefile 参数会将所有内容打包成一个独立的可执行文件
|
||
生成文件夹形式(包含多个文件)
|
||
bash
|
||
pyinstaller your_script.py
|
||
# 3. 常用参数说明
|
||
--name=APP_NAME:指定生成的可执行文件名称
|
||
--icon=ICON_PATH:指定程序图标(支持 .ico 格式)
|
||
--noconsole:打包成无控制台窗口的程序(Windows 下使用,适合 GUI 程序)
|
||
--hidden-import=MODULE_NAME:指定需要手动导入的模块
|
||
--add-data="SOURCE;DEST":添加额外的数据文件(Windows 用分号分隔,Linux/macOS 用冒号)
|
||
# 4. 针对你的文件搜索工具的打包示例
|
||
如果你的脚本名为 main.py,可以使用以下命令:
|
||
bash
|
||
# 基本打包(带控制台)
|
||
pyinstaller --onefile main.py
|
||
|
||
# 无控制台窗口(适合 GUI 程序)
|
||
pyinstaller --onefile --noconsole main.py
|
||
|
||
# 自定义名称和图标
|
||
pyinstaller --onefile --noconsole --name "文件搜索工具" --icon=search.ico main.py
|
||
|
||
|
||
|
||
5. 打包后的文件位置
|
||
打包完成后,会生成以下文件 / 文件夹:
|
||
dist/:包含生成的可执行文件
|
||
build/:打包过程中的临时文件
|
||
your_script.spec:打包配置文件(可用于高级配置)
|
||
通常你只需要关注 dist/ 目录下的可执行文件即可。
|
||
6. 可能遇到的问题及解决
|
||
如果打包后运行提示缺少模块,使用 --hidden-import 参数手动指定
|
||
数据文件需要使用 --add-data 参数添加,程序中需使用 sys._MEIPASS 访问
|
||
不同系统(Windows/macOS/Linux)需要在对应系统上打包
|
||
例如,如果你需要添加一些额外的数据文件,可以这样:
|
||
bash
|
||
pyinstaller --onefile --add-data "icons/*;icons" main.py
|
||
|
||
|
||
|
||
pyinstaller --onefile --noconsole --name "文件搜索工具" main.py
|