一、概述
目前有一個python腳本,需要在別的電腦中運行,安裝python環境太麻煩,封裝成exe文件,運行比較方便。
二、演示
環境說明
python版本:3.7.9
操作系統:windows 10
安裝模塊
pip3 installer pyinstaller
封裝
新建目錄test,目錄結構如下:
./├── conf.py
└── test.py
conf.py
#!/usr/bin/python3#-*- coding: utf-8 -*-
people_dict=[
{"name":"張三","age":'23'},
{"name":"李四","age":'21'}
]
test.py
#!/usr/bin/python3#-*- coding: utf-8 -*-
importconfimportjson
with open('ret.txt',encoding='utf-8',mode='w') as f:
f.write(json.dumps(conf.people_dict))
打開cmd窗口,進入test目錄,執行:
pyinstaller -F -c test.py
注意:test.py是主程序
輸出:
...7908INFO: checking