Created
December 27, 2013 11:53
-
-
Save hamukichi/8146081 to your computer and use it in GitHub Desktop.
IronPythonのpyc.pyでスクリプトをEXE化する際に、"No module named ..." エラーが出るという問題に対処するために、標準モジュールをすべて1つのDLLにまとめるスクリプト。おそらくもっとスマートな方法があるだろうと思う。http://blog.livedoor.jp/hamu_nbr/archives/20556672.html に掲載。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!D:/IronPython/ipy.exe | |
# -*- coding: utf-8 -*- | |
#D:\Source\gather_ipy_dll.py | |
#ipy.exeが存在するディレクトリ | |
IPYROOT = ur"D:\IronPython" | |
#出力するディレクトリ・ファイル名 | |
import os | |
OUTPUTDIR = ur"D:\Source" | |
OUTPUTFNAME = "StdLib" | |
#インポート | |
import sys | |
import shutil | |
sys.path.append(os.path.join(IPYROOT, "Tools", "Scripts")) #検索対象追加 | |
import pyc | |
def make_stdlib(odir = OUTPUTDIR, ofname = OUTPUTFNAME): | |
""" | |
標準モジュールをDLL化します。 | |
odir = <当スクリプトのあるディレクトリ> : 出力先のディレクトリ | |
ofname = "StdLib" : 出力ファイル名(拡張子除く) | |
""" | |
prev_dir = os.getcwd() | |
#DLLをIPYROOTに作成 | |
os.chdir(IPYROOT) | |
gb = [] | |
for dpath, dnames, fnames in os.walk(os.path.join(IPYROOT, "Lib")): | |
for fname in fnames: | |
if dpath.find("site-packages") == -1: | |
gb.append(os.path.join(dpath, fname)) | |
gb.append("/out:" + ofname) | |
pyc.Main(["/target:dll"]+gb) | |
#生成ファイルを移動 | |
shutil.move(os.path.join(IPYROOT, ofname + ".dll"), odir) | |
os.chdir(prev_dir) | |
def copy_ipydll(odir = OUTPUTDIR): | |
""" | |
ipyと同階層にあるDLLをコピーします。 | |
odir = <当スクリプトのあるディレクトリ> : 出力先のディレクトリ | |
""" | |
prev_chdir = os.getcwd() | |
os.chdir(IPYROOT) | |
for x in os.listdir(IPYROOT): | |
if os.path.splitext(x)[1] == ".dll": | |
shutil.copy(x, odir) | |
os.chdir(prev_chdir) | |
def main(): | |
make_stdlib() | |
copy_ipydll() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment