我正在使用cx_freeze將python文件傳輸到exe文件。問題是當我在setup.py中排除tkinter時,我可以成功生成exe文件,但是當執行exe文件時,它說No Module named tkinter
。如何在使用cx_freeze將腳本轉換爲.exe時包含tkinter?
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL"], "excludes": ["tkinter"]}
,但是當我嘗試包括tkinter
,它只是不能生成exe文件。
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL","tkinter"]}
File "C:\Users\changchun_xu\AppData\Local\Programs\Python\Python36-32\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'
你確定它說''沒有模塊命名爲tkinter「.'而不是'_tkinter'?也許還檢查[這](http://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-i-use-cx-freeze)問題 – abccd
感謝您的幫助!我再次查看信息,原始信息是「No module named'tkinter'」 – woniuwoniu
也許你可以嘗試下面的內容[that](http://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-通過輸入'os.environ ['TCL_LIBRARY'] = r'C:\ Program Files \ Python36-32 \ tcl \ tcl8.6''和 'os.environ,推薦使用i-use-cx-freeze/35706103) ['TK_LIBRARY'] = r'C:\ Program Files \ Python36-32 \ tcl \ tk8.6''在setup.py中。 **注意:用你實際的tcl和tk路徑替換路徑** – abccd