在cx_freeze中的TCL_LIBRARY [英] TCL_LIBRARY in cx_freeze

查看:123
本文介绍了在cx_freeze中的TCL_LIBRARY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cx_freeze库从我的python脚本构建exe文件。这是我的代码:

  import easygui 
easygui.ynbox('我继续吗?','标题', (是,否))

这是我的设置代码:

  import cx_Freeze 
import sys
import matplotlib

base = None

如果sys.platform =='win32':
base = Win32GUI

可执行文件= [cx_Freeze.Executable( tkinterVid28.py,base = base,icon = clienticon.ico)]

cx_Freeze.setup(
name = SeaofBTC-Client,
options = { build_exe:{ packages:[ easygui , matplotlib]}},
version = 0.01,
description = BTC交易应用程序之海,
可执行文件=可执行文件

然后出现此错误:

 文件 C:Python36\lib\site-packagescx_Freeze\finder.py,行485,位于_LoadPackage 
self._LoadModule(name,fp,path,info, deferredImports,父级)
文件 C:\Python36\ lib\site-packages\cx_Freeze\finder.py,第463行,位于_LoadModule
self._RunHook( load,module.name,module)
文件 C:\Python36 \lib\site-packages\cx_Freeze\finder.py,第536行,位于_RunHook
方法(自身,* args)中
文件 C:\Python36\lib\在load_tkinter
tclSourceDir = os.environ [ TCL_LIBRARY]
中的site-packages\cx_Freeze\hooks.py,行613中, C:Python32\lib\os。 py,行669中的__getitem__
从无
调高KeyError(key):$ TC $ {$}

解决方案

Easygui使用了一些Tkinter,因此在编译时必须包含Tkinter库。



是使用 include_files 争论



在脚本中添加以下参数的问题:

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

files = { include_files:[< ; Python的路径> /Python36-32/DLLs/tcl86t.dll,< Python的路径> /Python36-32/DLLs/tk86t.dll], clienticon.ico],包:[ easygui, matplotlib]}

下一个更改:

  options = { build_exe:{ packages:[ easygui, matplotlib]}},

至:

  options = { build_exe :files},

,然后一切正常。您的脚本现在应如下所示:

  import cx_Freeze 
import sys
import matplotlib

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

files = { include_files: [< Python的路径> /Python36-32/DLLs/tcl86t.dll,< Python的路径> /Python36-32/DLLs/tk86t.dll], packages:[ tkinter, easygui, matplotlib]}


base =无

如果sys.platform =='win32':
base = Win32GUI

可执行文件= [cx_Freeze.Executable( tkinterVid28.py,base = base,
icon = clienticon.ico)]

cx_Freeze.setup(
名称= SeaofBTC-Client,
选项= { build_exe:文件},
版本= 0.01,
描述= BTC交易应用程序之海,
可执行文件=可执行文件

脚本中还有另一个错误。因为您没有使用 include_files 参数来包含要使用的图标。它不会出现在可执行文件图标或输出中(如果在tkinterVid28.py文件中使用了它),则将生成错误。



哦,除非您有这样做的理由,否则我看不到您为什么导入了matplotlib。 Cx_Freeze在您尝试转换为可执行文件的脚本中检测到导入,而不是在安装脚本本身中检测到,但是在软件包中列出导入始终是个好主意。



I希望这能解决您的问题


i am trying to build an exe file from my python script using the cx_freeze library. this is my code:

import easygui
easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No'))

and this is my setup code:

import cx_Freeze
import sys
import matplotlib

base = None

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

executables = [cx_Freeze.Executable("tkinterVid28.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "SeaofBTC-Client",
    options = {"build_exe": {"packages":["easygui","matplotlib"]}},
    version = "0.01",
    description = "Sea of BTC trading application",
    executables = executables
    )

and then i get this error:

File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 485, in _LoadPackage
    self._LoadModule(name, fp, path, info, deferredImports, parent)
  File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 463, in _LoadModule
    self._RunHook("load", module.name, module)
  File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 536, in _RunHook
    method(self, *args)
  File "C:\Python36\lib\site-packages\cx_Freeze\hooks.py", line 613, in load_tkinter
    tclSourceDir = os.environ["TCL_LIBRARY"]
  File "C:\Python36\lib\os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'

解决方案

Easygui uses some Tkinter so when compiling it you must include the Tkinter libraries.

this should just be a question of using the include_files arguement

Add the following arguments to your script:

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

files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], , "clienticon.ico" ], "packages": ["easygui","matplotlib"]}

next alter:

options = {"build_exe": {"packages":["easygui","matplotlib"]}},

to:

options = {"build_exe": files},

and everything should work. Your script should now look like this:

import cx_Freeze
import sys
import matplotlib

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

files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter", "easygui","matplotlib"]}


base = None

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

executables = [cx_Freeze.Executable("tkinterVid28.py", base=base, 
icon="clienticon.ico")]

cx_Freeze.setup(
    name = "SeaofBTC-Client",
    options = {"build_exe": files},
    version = "0.01",
description = "Sea of BTC trading application",
executables = executables
)

There is another error in your script as well. Because you did not use include_files argument to include the icon you want to use. It would not appear in the executable icon or in the output (if you used it in your tkinterVid28.py file) this would generate an error.

Oh and unless you have a reason to do so I cannot see why you imported matplotlib. Cx_Freeze detects imports in the script you are trying to convert to an executable and not in the setup script itself but it is always a good idea to list them in packages.

I hope this sorted your problem

这篇关于在cx_freeze中的TCL_LIBRARY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆