0

I'm a french so sorry for my english. I actually create a Python 3.6.1 program that use tkinter, paramiko, telnetlib and many other, and I want to create an exe with cx_Freeze. With a "Hello World" program it success, but when I try with just Tkinter, it doesn't work. I have a screen of the error because I can't see it more than 0.5 seconds the terminal when I run the exe. So I join that screen with my setup.py.

setup.py:

import cx_Freeze
import os

os.environ['TCL_LIBRARY'] = r'C:\LOCAL_TO_PYTHON\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\LOCAL_TO_PYTHON\Python35-32\tcl\tk8.6'

executables= [cx_Freeze.Executable('exeTest.py',)]


cx_Freeze.setup(

    name = "leTest",
    options = {'built.exe':{'includes': ['tkinter','paramiko','telnetlib']}},
    version = "1.0",
    description = "Bonjour !",
    executables = executables,
)

error:

Traceback (most recent call last):
    File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\__startup.py", in line 12, in <module>
     __import__(name+"__init__")
    File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", in line 24, in <module>
      exec(code, m.__dict__)
    File "exeTest.py", line 9, in <module>
    File "C:\Python36\lib\tkinter\__init.py", in line 36, in <module>
     import _tkinter # If this fails your Python may not be configured fot Tk
  ImportError: DLL load failed: The specified module can not be found.

Thanks for reading and maybe for the help

Rafiki
  • 1
  • 2
  • This isn't actually the full traceback, so it'll be hard to diagnose, is there any way you can get the full traceback? Preliminarily, this error suggests that you're trying to import something and it's failing. – eijen May 15 '17 at 11:32
  • I can't send my screenshot :( – Rafiki May 15 '17 at 12:03
  • You should type up what's in the screenshot, anyway. It doesn't help anyone with the same problem if the error is in an image and can't be searched for later. – eijen May 15 '17 at 12:05
  • It's okay I write all the traceback – Rafiki May 15 '17 at 12:13
  • Possible duplicate of [ImportError DLL load failed importing \_tkinter](http://stackoverflow.com/questions/8724729/importerror-dll-load-failed-importing-tkinter) – eijen May 15 '17 at 12:18
  • No it doesn't work... – Rafiki May 15 '17 at 13:01

1 Answers1

0

Give this a try. Pretty sure this will assume your Python install is part of your PATH.

import sys
import os
from cx_Freeze import setup, Executable
import cx_Freeze
import tkinter
import os.path
import scipy

base = None

if sys.platform == 'win32':
    base = "Win32GUI"


PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

#os.environ['TCL_LIBRARY'] = r'C:\Users\matthew\Downloads\WinPython-64bit-3.5.3.0Qt5\python-3.5.3.amd64\tcl\tcl8.6'
#os.environ['TK_LIBRARY'] = r'C:\Users\matthew\Downloads\WinPython-64bit-3.5.3.0Qt5\python-3.5.3.amd64\tcl\tk8.6'

executables = [cx_Freeze.Executable("exeTest.py", base=base)]
addtional_mods = ['numpy.core._methods', 'numpy.lib.format']

packages = ["idna", "numpy",]
options = {
    'build_exe': {

        'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
            os.path.dirname(scipy.__file__),

         ],
        'includes': addtional_mods,
        'packages':packages,
    },

}

cx_Freeze.setup(
    name = "letest",
    options = options,
    version = "0.01",
    description = 'Bonjour',
    executables = executables
)
Gardener85
  • 369
  • 1
  • 9
  • It create a .exe as before, this is okay but it doesn't work...Same error but in a specific window so I can really read it. I just can't sent pics :( – Rafiki May 16 '17 at 13:21
  • Below is the almost exact setup I use when I make tkinter apps. I Tried editing out the stuff you didn't need but you can try it like this. If it's still not working I suspect it's due to your python not being part of your PATH: edit: I can't post the code in the comments, so I'm going to edit my asnwer – Gardener85 May 16 '17 at 15:04
  • also, I usually make sure to delete the build folder before making another one just in case. – Gardener85 May 16 '17 at 15:10