简体   繁体   中英

cx_Freeze Import Error: DLL load failed: The specified module could not be found

I wrote a basic program to keep track of customer names, vehicles, mileage, and date, and it also has an option for the user to choose to see a company logo that I drew using the turtle module. Then I used cx_freeze to freeze it as an executable, and everything froze and a build file with all the necessary files and folders and an executable was created, but when I run the .exe file I can't choose my option to view the company logo. I continue to get this error when running it in CMD:

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.

The top part of the error is the actual running of my code and you can see the 4 options; all of these work other than #3.

I have checked in the tkinter documentation and the cx_Freeze documentation and cannot find anything that I am doing wrong. Here is my setup.py file that I am using to build my executable:

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')])

The tkinter module in the "includes" for my build_exe, I have tried to remove and spell it just tkinter, I have tried to put both tkinter and turtle, and each individual module in "packages" instead of "includes". I have tried every option that relates to my situation in the cx_Freeze documentation with no luck.

I found another question that closely relates to mine: import _tkinter # If this fails your Python may not be configured for Tk There are no answers to this question and mine somewhat differs.

I am running Windows 10 OS and Python 3.6.1 Also the script does work when ran from the Python IDLE

for the icon what you will need to do is in your setup.py, under the os.environ part set base equal to none(base=None) and then in the executables variable, right after you put OilExchange.py you need to put a comma, say base equals base(base=base), put another comma, write icon and set it equal to your icon directory. Here is my example executables = [Executable("texteditor.py", base=base, icon="books_logo.ico")]

here is a more fuller version for clarification

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")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM