LoginSignup
3
5

pyファイルexe化を1クリックで出来るようにする【pyinstaller, bat, Windows】

Last updated at Posted at 2024-03-12

結論

pyinstaller make exe file.bat
cd /d %~dp0
for %%f in (*.py) do set FILE=%%f
pipenv run pip install pyinstaller
pipenv run pip install -r requirements.txt
pipenv run pyinstaller %FILE% --onefile
pipenv --rm

動作環境

Windows

必要な準備

pipenvをインストール

pip install pipenv

requirements.txtを書く

pyファイルでimportしている、必要なライブラリをrequirements.txtにまとめてください。
(標準ライブラリのみならrequirements.txtは不要)
requirements.txtの書き方は各自でググってください。
requirements.txtはexe化したいpyファイルと同じディレクトリに保存してください。
https://note.nkmk.me/python-pip-install-requirements/

ディレクトリがこういう感じになるかなと。
image.png
あとはbatを実行すればdistフォルダが出来ますので、その中にお目当てのexeファイルがあるかなと。
image.png

やってはいけないこと

この.batファイル自体の名前を「pyinstaller.bat」という名前にしないこと。
pyinstaller実行時に、pyinstaller.batが参照されるため、無限ループになります。

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5