将 Tcl/Tk 链接到 Python 2.5

发布于 2024-08-12 11:00:02 字数 613 浏览 2 评论 0原文

我有一个现有的 Python 2.4,它可以与 tkinter 正常工作,因为我使用

python

import _tkinter

对其进行了测试 <块引用> <块引用>

导入 Tkinter Tkinter._test()

现在,我已经安装了 python 2.5.2,但是当我尝试相同的测试(使用较新的版本)时,它会返回(但相同的测试适用于以前的版本)

ImportError: No module named _tkinter

我知道tcl8.5 和 tk8.5 安装在我的机器上,因为以下命令返回

tcl 所在的 位置 tcl: /usr/lib/tcl8.4 /usr/local/lib/tcl8.5 /usr/local/lib/tcl8.4 /usr/share/tcl8.4

其中 tk tk: /usr/lib/tk8.4 /usr/local/lib/tk8.5 /usr/share/tk8.4

有什么想法如何让我的新 python 版本与 tkinter 一起工作吗?

I have an existing Python 2.4 and it is working properly with tkinter as I tested it using

python

import _tkinter

import Tkinter
Tkinter._test()

Now, I have installed python 2.5.2 but when I try the same tests (with the newer version), it returns (but the same tests are working for the previous version)

ImportError: No module named _tkinter

I know that tcl8.5 and tk8.5 are installed on my machine as the following commands return there locations

whereis tcl
tcl: /usr/lib/tcl8.4 /usr/local/lib/tcl8.5 /usr/local/lib/tcl8.4 /usr/share/tcl8.4

whereis tk
tk: /usr/lib/tk8.4 /usr/local/lib/tk8.5 /usr/share/tk8.4

Any ideas how do I make my newer python version work with tkinter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-08-19 11:00:02

您找到的文件用于直接链接到 tcl/tk。 Python 还依赖于另一个库:_tkinter.so。它应该位于 /usr/lib/python2.5/lib-dynload/_tkinter.so 中。
你是如何安装python2.5的?如果您使用 Debian 或 Ubuntu,则需要安装 python-tk 软件包才能获得 Tkinter 支持。

如果存在 _tkinter.so 文件,则您的环境可能会导致问题。
如果

python -E -c“导入
Tkinter;Tkinter._test()"

成功,但是

python -c“导入
Tkinter;Tkinter._test()"

失败,那么问题出在您的环境设置方式上。检查 PYTHONPATH 的值是否设置正确。

The files you found are for linking directly to tcl/tk. Python depends on another library as well: _tkinter.so. It should be in /usr/lib/python2.5/lib-dynload/_tkinter.so.
How did you install python2.5? If you are using Debian or Ubuntu you need to install the python-tk package to get Tkinter support.

If the _tkinter.so file is there, your environment could be causing problems.
If

python -E -c "import
Tkinter;Tkinter._test()"

suceeds, but

python -c "import
Tkinter;Tkinter._test()"

fails, then the problem is with how your environment is set up. Check the value of PYTHONPATH is set correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文