cx_Freeze与Tkinter

时间:2017-05-15 11:06:07

标签: python tkinter cx-freeze

我是法国人,对我的英语很抱歉。 我实际上创建了一个使用tkinter,paramiko,telnetlib和许多其他的Python 3.6.1程序,我想用cx_Freeze创建一个exe。有了“Hello World”程序,它成功了,但是当我尝试使用Tkinter时,它不起作用。我有一个错误的屏幕,因为当我运行exe时,我看不到超过0.5秒的终端。所以我用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,
)

的 错误:

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.

感谢阅读,也许是为了帮助

1 个答案:

答案 0 :(得分:0)

试一试。很确定这会假设您的Python安装是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
)