2016-05-24 22 views
1

私はPython 3.5で書かれたスクリプトからスタンドアロンのexeファイルを作成しようとしていますが、cx_Freezeを使用するとPythonのないコンピュータでも実行できます。cx_freezeで作成されたtkinter exeを実行する際にエラーが発生しました

プログラム自体は、tkinterを使用した簡単なUIを備えた小さな電卓です。 Windowsを使用しています。

このような設定スクリプトを作成しました。

import sys 
from cx_Freeze import setup, Executable 
# replaces commandline arg 'build' 
sys.argv.append("build") 

filename = "Widgets_tmp.py" 
base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 
setup(
    name = "Widgets", 
    version = "1.0", 
# options={"build_exe": {"packages": ["tkinter"]}}, 
    description = "cx_Freeze Tkinter script", 
    executables = [Executable(filename, base=base)]) 

これはexeを実行しようとするまで問題なく実行されます。そして、私はこのエラーを取得する:

Traceback (most recent call last): 
    File "C:\python64\lib\site-packages\cx_freeze\initscripts\Console.py" 
line 21, in <module> 
    exec(code, m.__dict__) 
    File "Widgets_tmp.py", line 1, in <module> 
    File "C:\python64\lib\tkinter\__init__.py", line 35, in <module> 
    import _tkinter#If this fails you Python may not be configured for Tk 
ImportError: DLL load failed: 

が、私はコードでコメントアウトコードでてmanualyのTkinterを含むしようとしたし、代わりに「パッケージ」のが、同じ結果を「含む(includes)」に。私はソースからのサンプルコードを凍結しようとしたが、同じエラーを取得

import tkinter as tk 

おそらく、私はWidgets_tmp.pyでその行1は、このようになりますと言う必要があります。どちらのコードもPythonを使って完璧に動作します。

私も使ってみました:

options={"build_exe": {"includes": ["tkinter"]}}, 

が、運。

+0

'tkinter'に' --include-modules'コマンドライン引数を使う必要があるかもしれません。 http://stackoverflow.com/questions/2223128/cx-freeze-importerror-cannot-import-name – martineau

+0

を参照してください。その質問は、tkinterをインクルードオプションとパッケージに追加しようと考えてくれましたが、それはできませんでした。コマンドラインをもう一度コーディングして使うのは全く新しいことです。 DOSの思い出が戻ってきている。私は単に--include-modulesを "python Widgets_tmp.py Build"コマンドに追加すべきですか、何とかtkinterを指定する必要がありますか? – Brute

+0

リンクされた質問に対する答えを理解する方法は、あなたが '--include-modules'コマンドラインオプションを使って' tkinter'モジュールを組み込む必要があるということです。あるいは 'includes = 'あなたのsetup.pyスクリプトの行。 – martineau

答えて

4

私のPCのsetup.pyを修正することで、tkinter exeが正常に動作しました。

OS = win7の、パイソン= 3.5.2、cx_freeze = 5.0

setup.py:

includes  = [] 
include_files = [r"C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python35-32\DLLs\tcl86t.dll", \ 
       r"C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python35-32\DLLs\tk86t.dll"] 

setup(
    name = "Test", 
    version = "1.0", 
    options = {"build_exe": {"includes": includes, "include_files": include_files}}, 
    executables = [Executable("test.py", base=base)] 
) 

ご使用の環境のために(USERNAME)を変更する必要があります。

関連する問題