LoginSignup
20
27

More than 5 years have passed since last update.

Anaconda環境で作成したPythonプログラムをexe化した話。

Last updated at Posted at 2018-10-01

Anaconda環境で作成したPythonプログラムをexe化した話。

環境

  • Win7 Pro
  • Anaconda 5.2(Python 3.6 Version)
  • Python 3.6.5

なぜexe化したかったのか

波形解析をPythonで楽にできることを知り、Python TUEEEEしてた。
しかし、Pythonスクリプトをそのまま実行するためにはPythonがインストールされている環境でないとダメと知る。
ならば実行形式にしてやればいいじゃん←イマココ

exe化するには

Pyinstallerなるものを使ったら幸せになれるらしい。

Pyinstallerをインストールする

Anaconda環境にpipでパッケージをインストールするを参考にさせていただいて、Pyinstallerをインストールしようとする。

プロキシにひっかかった……。

proxyかんでる社内環境でpip/anacondaを動かすときに注意事項。を参考にさせていただいて、プロキシを通過しPyinstallerをインストール!

いざ、exe化へ

exe化したいPythonスクリプトはこんなの。

wave.py
from scipy.optimize import curve_fit
import seaborn as sns

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

filepath = input('please input file path.')
filename = pd.read_csv(filepath, encoding="SHIFT-JIS")
listT = []
listV = []
listT = filename['time']
listV = filename['value']

type = input('please input type.\n1:curve\r2:average')
if type == '1':
    res = np.polyfit(listT,listV,10)
    y2 = np.poly1d(res)(listT)
    plt.figure(figsize=(20,10))
    plt.plot(listT,listV,label='ori')
    plt.plot(listT,y2,label='curve_fit')
else:
    num = 10000
    b = np.ones(num)/num
    y2 = np.convolve(listV, b, mode='same')
    plt.figure(figsize=(20,10))
    plt.plot(listT,listV, label='ori')
    plt.plot(listT,y2, label='ave')

plt.legend()
plt.show()

input()

pyinstaller wave.pyを実行。

結果

Recursion error : maximum recursion depth exceeded

再帰回数が多いらしい。
pyinstaller wave.py実行時に生成されるwave.specをpyinstaller creating EXE RuntimeError: maximum recursion depth exceeded while calling a Python objectを参考にさせていただいて、変更する。

pyinstaller wave.specを実行。

結果

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 128: invalid start byte

読み込みファイルをUTF-8で保存し直しても解決ならず……。
teratailで質問(python3のpyinstallerを使用したexe化について)する。

c:\users\user\anaconda3\lib\site-packages\PyInstaller\compat.py の370行目

out = out.decode(encoding)
 変更
out = out.decode(encoding, errors='ignore')

pyinstaller wave.specを再度実行。

結果 できた!ブラボー!!!!

やったね、たえちゃん。pythonスクリプトがexe化できたよ!!

追記

exe化できたにはできたが実行開始までが糞重い。(我慢できないくらい。時間は計ってない。)
cx_Freezeなるものの方がなにやら早いらしい。
cx_Freezeも調べてみないとなあ。

20
27
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
20
27