2017-06-04 144 views
0

我編寫了一個基本程序來跟蹤客戶名稱,車輛,里程和日期,並且還有一個供用戶選擇查看的選項我用烏龜模塊繪製的公司徽標。然後,我用cx_freeze凍結它作爲一個可執行文件,並且所有東西都凍結了,包含所有必要文件和文件夾以及可執行文件的構建文件被創建,但是當我運行.exe文件時,我無法選擇我的選項來查看公司商標。我不斷地得到這個錯誤在CMD運行時:cx_Freeze導入錯誤:DLL加載失敗:找不到指定的模塊

C:\Users\hdaug\Documents\Holden's Personal\PythonPrograms\CX\build\exe.win-amd64-3.6>OilChangeEx.exe 
At Holden's Oil Change we use our custom built Python program to keep track of customer records and to display our company logo!! 
Select and option from the menu! 
1 Current Customers 
2 New Customers 
3 Company Logo 
4 Quit 
Select an option: 3 
Traceback (most recent call last): 
    File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run 
    module.run() 
    File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run 
    exec(code, m.__dict__) 
    File "OilChangeEx.py", line 282, in <module> 
    File "OilChangeEx.py", line 56, in main 
    File "OilChangeEx.py", line 77, in commandChoice 
    File "OilChangeEx.py", line 176, in Turt 
    File "C:\Program Files\Python36\lib\turtle.py", line 107, in <module> 
    import tkinter as TK 
    File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 36, in <module> 
    import _tkinter # If this fails your Python may not be configured for Tk 
ImportError: DLL load failed: The specified module could not be found. 

錯誤的頂部是我的代碼的實際運行,你可以看到4個選項;所有這些工作都不是#3。

我檢查了tkinter文檔和cx_Freeze文檔,找不到我做錯的任何事情。下面是我使用來構建我的可執行我的setup.py文件:

from cx_Freeze import setup, Executable 
import os 

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6' 
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36\tcl\tk8.6' 

build_exe_options = {"includes": ["turtle","_tkinter"]} 

setup(name='OilChange', 
     version='0.1', 
     description='OilChangeRecords', 
     options = {"build_exe": build_exe_options}, 
     executables = [Executable('OilChangeEx.py')]) 

在「包括」我的build_exe,我試圖刪除和拼寫它只是Tkinter的Tkinter的的模塊,我曾嘗試將tkinter和turtle,以及每個單獨的模塊放在「包」中而不是「包含」。我嘗試了所有與cx_Freeze文檔中的情況相關的選項,但都沒有運氣。

我發現了另一個與我密切相關的問題:import _tkinter # If this fails your Python may not be configured for Tk這個問題沒有答案,我的情況有所不同。

我運行Windows 10操作系統和Python 3.6.1 同樣的腳本不工作時從Python IDLE

回答

0

的圖標是什麼,你需要做的就是在你的setup.py,操作系統下運行.environ部分設置base等於none(base = None),然後在可執行文件變量中,在您放入OilExchange.py後,您需要輸入一個逗號,例如base等於base(base = base),再放一個逗號,寫入圖標並將其設置爲等於您的圖標目錄。這是我的例子executables = [Executable("texteditor.py", base=base, icon="books_logo.ico")]

-1

這裏澄清一個更豐滿的版本

from cx_Freeze import setup, Executable 
import sys 
import os 

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6' 
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36\tcl\tk8.6' 

# Dependencies are automatically detected, but it might need fine tuning. 
#build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]} 

base = None 
if sys.platform == 'win32': 
    base = 'Win32GUI' 
setup(
    name = "VBtEditor", 
    options = {"build_exe": {"packages":["tkinter", "os", "cx_Freeze"], "include_files": ["books_logo.ico"]}}, 
    version = "0.01", 
    description = "Professional text editor part of the VIRTUAL BUREAU", 
    executables = [Executable("texteditor.py", base=base, icon="books_logo.ico")] 
+0

你應該添加到您原來的答案,而不是發佈一個新的 – Phydeaux

相關問題