【问题标题】:_tkinter.TclError: can't find package comm_tkinter.TclError:找不到包通讯
【发布时间】:2020-11-17 16:56:28
【问题描述】:

在尝试使用 comm 包时遇到这个问题:

>>> interp = tkinter.Tcl()
>>> interp.eval('package require comm')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_tkinter.TclError: can't find package comm

我在 Windows 10 上使用 python 3.6.8

【问题讨论】:

  • 欢迎来到 SO Sblu,你能分享产生这个错误的代码吗?
  • 假设是this comm package,你安装tcllib了吗?
  • @shawn,是的,就是那个通讯包。一般来说,我是 tcl 的新手。你如何检查它是否已经安装?
  • @cbo,代码贴出来了
  • 我的错误@Sblu,将在时间限制过后相应地纠正我的反对意见。

标签: python tcl


【解决方案1】:

如果你知道comm 包的安装目录(包含pkgIndex.tcl 的目录或直接父目录),你应该确保它在Tcl 的auto_path 之前试图package require 包裹。您需要这样做的功能是:

def add_library_directory(tcl_context, directory_name):
    tcl_context.eval("lappend auto_path {}".format(
        # This does the trick to make the string substitution fully safe
        tkinter._stringify(directory_name)))

interp = tkinter.Tcl()
# Up to you to actually find the location...
add_library_directory(interp, "/path/to/dir")
interp.eval('package require comm')

有关 tkinter._stringify 的详细信息,尽管它非常有用,但它的文档却大量不足,请参阅另一个 Stack Overflow 问题:

【讨论】:

  • 谢谢@Donal。不幸的是,这有助于推进,但没有解决问题。我可以通过移动目录来临时安装它,但我更愿意修复脚本。这到底是在哪里搜索的? '''>>> interp.eval('package require comm') Traceback(最近一次调用最后):文件“”,第 1 行,在 _tkinter.TclError:找不到可用的 init。 tcl 在以下目录中: C:/Python36/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.6/library C: /tcl8.6.6/library'''
  • 我意识到这与这里讨论的主题有些不同,现在我只是通过移动目录来取得进展而不是更优雅的解决方案来作弊:stackoverflow.com/questions/29320039/…
【解决方案2】:

解决方案的摘要是 @Donal 解释的 https://stackoverflow.com/a/64884895/14656464,然后可能是下一个解决方案:Python Tkinter throwing Tcl error 通过将包含 comms 库的 tcl lib 的脱机版本指向 python 环境期望的位置。

【讨论】:

    猜你喜欢
    • 2019-05-25
    • 2020-12-19
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 2011-09-04
    • 2013-05-04
    • 1970-01-01
    • 2020-03-04
    相关资源
    最近更新 更多