Python 版本和 Tcl/Tk 兼容性

发布于 2024-10-26 13:27:42 字数 573 浏览 5 评论 0原文

我已经安装了 Tcl 和 Tk,并且遇到了熟悉的“没有名为 _tkinter 的模块”错误。

我的“python”Bash 命令运行 Python 版本 2.4.2,但 Synaptic 说我有 2.6。 6已安装。我什至尝试安装3.0,但也失败了。

我自己配置​​并构建了 Tcl/Tk tarball,并尝试使用 synaptic 包。

“wish”和“tclsh”命令都有效,所以我知道模块已安装,但我无法让 Python 识别它们。此外,我一生都无法弄清楚我应该使用哪个版本的 Python 以及如何让我的 Bash 命令使用该版本。

我没有看到任何删除 2.4.2 的选项,如果我删除 2.6.6,它会删除似乎是我的大多数其他软件包的内容(我知道这很夸张)。

我真的不知道从这里去哪里,所以任何指导将不胜感激。

更新:

我必须重新安装 python-tk 包,2.6 可以导入它。现在我只需要弄清楚如何删除 2.4,以免以后搞砸。

I have installed Tcl and Tk, and I am running into the oh-so-familiar "No module named _tkinter" error.

My 'python' Bash command runs Python version 2.4.2, but Synaptic says I have 2.6.6 installed. I even tried installing 3.0, but that also failed.

I have configured and built the Tcl/Tk tarballs myself, and tried using the synaptic packages.

Both "wish" and "tclsh" commands work, so I know that the modules are installed, but I can't for the life of me get Python to recognize them. Moreover, I can't for the life of my figure out which version of Python I should be using and how to get my Bash command to use that one.

I don't see any options for 2.4.2 removal, and if I remove 2.6.6, it removes what seems to be most of my other packages (exaggeration, I know).

I really don't know where to go from here, so any guidance would be greatly appreciated.

Update:

I had to reinstall the python-tk package, and 2.6 is able to import it. Now I just need to figure out how to remove 2.4 for the sake of not screwing something up later on.

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

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

发布评论

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

评论(2

下壹個目標 2024-11-02 13:27:42

这里有一些命令可以帮助您诊断问题。

首先,尝试运行附加版本号的 python 命令。自从
Synaptic 表示您已安装 2.6.6,您应该能够运行 python2.6 来
获取该版本:

(type 'python' and hit TAB to see possible completions)

% python<tab>
python
python2.6
python3.1

如果您仍然无法运行 TK,请找到 _tkinter.so 模块所在的位置
你的系统。它可能在 2.6.6 解释器找不到的地方。以下是 Ubuntu Lucid 上 python-tk 软件包的安装位置:

% find /usr -name '_tkinter*'
/usr/lib/python2.6/lib-dynload/_tkinter.so

Here are a few commands which could help you diagnose your problem.

First, try to run the python command with the version number appended. Since
Synaptic says you have 2.6.6 installed you should be able to run python2.6 to
get that version:

(type 'python' and hit TAB to see possible completions)

% python<tab>
python
python2.6
python3.1

If you still can't get TK to run, find where the _tkinter.so module lives on
your system. It may be somewhere the 2.6.6 interpreter can't find it. Here's the location as installed by python-tk package on Ubuntu Lucid:

% find /usr -name '_tkinter*'
/usr/lib/python2.6/lib-dynload/_tkinter.so
梦在夏天 2024-11-02 13:27:42

只是为那些登陆此页面的人提供有关 Python 3+ 的更新(就像我一样)。要在基于 Debian 的 Linux (Ubuntu) 上运行 tkinter,需要 python3 以及 python3-tk(它不在库中) list):

sudo apt-get install python3
sudo apt-get install python3-tk

另外,脚本需要将其作为第一行:

#! /usr/bin/python3

至少这是我解决问题的方法。

Just an update for those who land on this page, regarding Python 3+ (like I have). To run tkinter on a Debian-based Linux (Ubuntu), python3 is needed, as well as python3-tk (it's not in the library list):

sudo apt-get install python3
sudo apt-get install python3-tk

Also, the script needs to have this as the first line:

#! /usr/bin/python3

At least that is how I solved the problem.

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