LoginSignup
4
6

More than 5 years have passed since last update.

IronPython2でexeを作成と、つまづいた点

Last updated at Posted at 2017-09-28

IronPython3がまだ微妙に感じたのでIronPython2を使ってみることにした。

LIB\〜.pyを含められない(?)ため
TH-wbRadStudio で php7.1をexe化 (python3.6も可) - Qiitaの方が使いやすい気がする。

Download

https://github.com/IronLanguages/main/releases
から ipy-2.7.7ではなくipy-2.7.6.3 をダウンロード。
今回はmsiではなく、zipの方をダウンロードした。

.exe作成テスト (.dllも作成されます。)

a.py
print 'hello'
exe作成
ipy "Tools\Scripts\pyc.py" /target:exe /main:a.py a.py 
exe作成(スタンドアロン版)
ipy "Tools\Scripts\pyc.py" /standalone /target:exe /main:a.py a.py 

IronPython2直下にあるdll群も一緒に置くとa.exeが動きました。

dlls.png

(メモ) /standalone オプションを追加した時の出力
スクリーンショット_2017-09-29_07-04-26.png

失敗例

ipy.exe がある箇所以外で実行しようとすると以下エラーになった。
a.dllも一緒に配布することが必要でした。

clash.png

最新の ipy-2.7.7 だとpycでエラーとなった。

日本語の場合
ipy.exe" "C:\IronPython 2.7\Tools\Scripts\pyc.py" /target:exe /main:Test1.py
..(略)
Compiling...
Traceback (most recent call last):
 File "C:\IronPython 2.7\Tools\Scripts\pyc.py", line 332, in <module>
 File "C:\IronPython 2.7\Tools\Scripts\pyc.py", line 327, in Main
 File "C:\IronPython 2.7\Tools\Scripts\pyc.py", line 181, in GenerateExe

SystemError: あいまいな一致が見つかりました。 
英語の場合
Traceback (most recent call last):
  File "pyc.py", line 332, in <module>
  File "pyc.py", line 327, in Main
  File "pyc.py", line 181, in GenerateExe
SystemError: Ambiguous match found.

文字コードに難あり

IronPythonでShift JISのテキストファイルを取り扱う場合の注意点 | OPC Diaryによると

IronPythonではテキストデータはあらかじめutf-8にしておく方が無難。
どうしてもshift_jisを使うならコーデックとしてmbcsを指定する。

import sys
sys.path.append(r'..\LIB')

func set_encoding():
    import sys
    import codecs
    charset = 'mbcs'
    sys.stdin  = codecs.getreader(charset)(sys.stdin)
    sys.stdout = codecs.getwriter(charset)(sys.stdout)

set_encoding()
4
6
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
4
6