LoginSignup
3
8

More than 3 years have passed since last update.

PythonファイルをEXE化してみた(Recursion error対応済)

Posted at

外部ライブラリのインストール

PyファイルをEXE化するためにはライブラリが必要です。
以下のコマンドでインストールします。

$ pip install pyinstaller

exe化するには以下のように入力します。
-–onefile とつけると1つのファイルになり、
-–noconsole はコンソールが表示されなくなります。
オプションを付ける場合は以下のようにコマンド入力します。

$ pyinstaller pythonファイル名 --onefile --noconsole

成功するとdistというフォルダが新規に作成され、
EXEファイルが保存されます。

これですんなりEXE化出来ればいいのですが、
以下のようなエラーが表示され、失敗することがあります。

Recursion error : maximum recursion depth exceeded

上記エラーが表示された場合は、以下の手段でリトライします。

まず、「ファイル名.spec」というファイルがpyinstaller実行完了時に保存されています。これをメモ帳などで開いてから、以下のように2行追記してください。

# -*- mode: python ; coding: utf-8 -*-
import sys #追記
sys.setrecursionlimit(10000) #追記
block_cipher = None

追記出来たら、PowerShellを開きpyinstallerを実行するのですが、
1点注意が必要です。pyファイルではなく、先ほど編集したspecファイルに対してpyinstallerを実施します。

$ pyinstaller 編集したspecファイル.spec --onefile --noconsole

これで無事EXE化出来るかと思います。
EXEファイルはdistというフォルダに新規に作成されます。

3
8
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
8