自動化腳本,每次在別的電腦上使用都需要配置環境,試著 打包與本機環境分離
打包項目,其中包含配置文件,讀取本地文件
打包命令
開發完畢後,查看用到庫
pip freeze > reqirements. txt
安裝依賴庫
pip install -r reqirements . txt
-i 給應用程序添加圖標
-F 只生成一個exe格式的文件
-D 創建一個目錄,包含exe文件,但會依賴很多文件(默認選項)
-c 有黑窗口
-w 去掉黑窗口
切換到文件目錄執行命令
pyinstaller -D xxx.py -n 項目名稱 -i 路徑
pyinstaller -D -w -i logo.ico Main_ITAA.py
配置.spec文件
# -*- mode: python ; coding: utf-8 -*-
import sys
import os.path as osp
sys.setrecursionlimit(5000)
SETUP_DIR = 'D:\\dome_exe\\'
block_cipher = None
a = Analysis(['main.py',
SETUP_DIR+'case\\test_case.py',
SETUP_DIR+'commons\\common.py',
SETUP_DIR+'logs\\user_log.py',
SETUP_DIR+'uitl\\excel.py',
SETUP_DIR+'uitl\\keylib.py',
SETUP_DIR+'uitl\\logical_processing.py',
SETUP_DIR+'uitl\\setdriver.py',
SETUP_DIR+'uitl\\video_recording.py'],
pathex=['D:\\dome_exe\\'],
binaries=[],
datas=[(SETUP_DIR+'driver','driver'),
(SETUP_DIR+'logs\\logs','logs\\logs'),
(SETUP_DIR+'data','data'),
(SETUP_DIR+'report','report'),
(SETUP_DIR+'images','images'),
(SETUP_DIR+'video','video'),
],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='aaaaaaa',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')