pyinstaller
PythonのEXE化
Pythonの実行環境が整っていない人にも使ってもらえるように、Tkinter等でGUI化したファイルをEXE化して配布するためには、nuitkaやpyinstallerが必要
pyinstaller
cd ctkproject
pip install pyinstaller
pyinstaller --onefile --windowed ctk.py
# アイコンを変えたい場合
pyinstaller --onefile --windowed --icon=icon.ico ctk.py
# 画像やDBファイルなど外部ファイルがある場合
pyinstaller --onefile --windowed --add-data "icon-search.png;." ctk.py
# 画像が複数ある場合(JSONファイルもadd-dataすること!)
pyinstaller --onefile --windowed --add-data "icon-search.png;."
--add-data "icon-pen.png;." --add-data "icon-update.png;." --add-data "icon-trashbox.png;."
--add-data "custom.json;." ctk.py| –onefile | スクリプト実行に関するファイルを1つのexeファイルにまとめてくれる | |
| –windowed | コンソール画面を出さない | |
| –noconsole | exeファイル実行時に表示されるコンソール画面を非表示にできる |
完成したexeファイルがdist/ctk.exe に作成される
Exe化Error
ERROR: Do not run pyinstaller from C:\Windows\System32\ctkproject. cd to where your code is and run pyinstaller from there. Hint: You can open a terminal where your code is by going to the parent folder in Windows file explorer and typing cmd into the address bar.というエラーが発生した
pyinstallerを「C:\Windows\System32」から実行するとセキュリティの関係で実行できないという意味
ctk.pyなどを
cd C:\Users\ユーザー名\Desktop\ctkprojectなどに移してから再度pyinstallerを実行すること
EXEファイルの配布方法
–add-dataしているなら icon-search.pngはctk.exe内に埋め込まれているため、icon-search.pngは配布する必要がない
配布するのはEXEファイルだけ
配布方法はctk.exeをそのままZIPにしてWordPressにアップロードし、リンクをaタグでおいてクリックしてもらうだけ
※exeファイルをWordPressに直接アップロードすることができない
※USB依存の機能がある場合は、USBがないとアプリが起動できないので、説明書を添付するとよい
BACK