Linux 为 Python 安装 tkinter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4783810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install tkinter for Python
提问by Karan
I am trying to import Tkinter
. However, I get an error stating that Tkinter
has not been installed:
我正在努力import Tkinter
。但是,我收到一条错误消息,指出Tkinter
尚未安装:
ImportError: No module named _tkinter, please install the python-tk package
I could probably install it using synaptic manager (can I?), however, I would have to install it on every machine I program on. Would it be possible to add the Tkinter library into my workspace and reference it from there?
我可能可以使用突触管理器安装它(可以吗?),但是,我必须在我编程的每台机器上安装它。是否可以将 Tkinter 库添加到我的工作区并从那里引用它?
采纳答案by 9000
It is not very easy to install Tkinter locally to use with system-provided Python. You may build it from sources, but this is usually not the best idea with a binary package-based distro you're apparently running.
在本地安装 Tkinter 以与系统提供的 Python 一起使用不是很容易。您可以从源代码构建它,但是对于您显然正在运行的基于二进制包的发行版,这通常不是最好的主意。
It's safer to apt-get install python-tk
on your machine(s).
(Works on Debian-derived distributions like for Ubuntu; refer to your package manager and package list on other distributions.)
apt-get install python-tk
在您的机器上更安全。(适用于 Debian 衍生发行版,例如 Ubuntu;请参阅其他发行版上的包管理器和包列表。)
回答by Corey Goldberg
you will need the package and its dependencies.
您将需要该包及其依赖项。
since you mentioned synaptic, you must be using a Debian based system. one way to get what you need:
既然您提到了突触,那么您必须使用基于 Debian 的系统。获得所需内容的一种方法:
sudo apt-get install python-tk
回答by Simon
If, like me, you don't have root privileges on your network because of your wonderful friends in I.S., and you are working in a local install you may have some problems with the above approaches.
如果像我一样,由于您在 IS 中的好朋友,您在您的网络上没有 root 权限,并且您在本地安装中工作,则上述方法可能会遇到一些问题。
I spent ages on Google - but in the end, it's easy.
我在 Google 上花了很长时间 - 但最终,这很容易。
Download the tcl and tk from http://www.tcl.tk/software/tcltk/download.htmland install them locally too.
从http://www.tcl.tk/software/tcltk/download.html下载 tcl 和 tk并在本地安装它们。
To install locally on Linux (I did it to my home directory), extract the .tar.gz files for tcl and tk. Then open up the readme files inside the ./unix directory. I ran
要在 Linux 上本地安装(我是在我的主目录中安装的),请为 tcl 和 tk 提取 .tar.gz 文件。然后打开 ./unix 目录中的自述文件。我跑了
cd ~/tcl8.5.11/unix
./configure --prefix=/home/cnel711 --exec-prefix=/home/cnel711
make
make install
cd ~/tk8.5.11/unix
./configure --prefix=/home/cnel711 --exec-prefix=/home/cnel711 --with-tcl=/home/cnel711/tcl8.5.11/unix
make
make install
It may seem a pain, but the files are tiny and installation is very fast.
这可能看起来很痛苦,但文件很小,安装速度非常快。
Then re-run python setup.py build
and python setup.py install
in your python installation directory - and it should work. It worked for me - and I can now import Tkinter etc to my heart's content - yipidy-yay. An entire afternoon spent on this - hope this note saves others from the pain.
然后重新运行python setup.py build
并python setup.py install
在您的python安装目录中 - 它应该可以工作。它对我有用 - 我现在可以将 Tkinter 等导入到我的内心深处 - yipidy-yay。一整个下午都花在了这上面——希望这张纸条能让其他人免于痛苦。
回答by user1497423
If you are using Python 3 it might be because you are typing Tkinter
not tkinter
如果您使用的是 Python 3,那可能是因为您输入的Tkinter
不是tkinter
回答by Neil
Actually, you just need to use the following to install the tkinter for python3:
实际上,您只需要使用以下内容来安装 python3 的 tkinter:
sudo apt-get install python3-tk
In addition, for Fedora users, use the following command:
此外,对于 Fedora 用户,请使用以下命令:
sudo dnf install python3-tkinter
回答by BartoszKP
For Python 2.7:
对于 Python 2.7:
You don't need to download Tkinter - it's an integral part of all Python distributions (except binary distributions for platforms that don't support Tcl/Tk).
您不需要下载 Tkinter - 它是所有 Python 发行版的组成部分(不支持 Tcl/Tk 的平台的二进制发行版除外)。
as it says here. In my case, on Windows, what helped was reinstalling the Python distribution. Probably a long time ago I had unchecked the "Tcl/Tk" installation feature. After reinstalling all works fine and I can import _tkinter
and import Tkinter
.
因为它说在这里。就我而言,在 Windows 上,重新安装 Python 发行版有帮助。可能很久以前我取消了“Tcl/Tk”安装功能的勾选。重新安装后一切正常,我可以import _tkinter
和import Tkinter
.
回答by gon1332
If you're using Python 3
then you must install as follows:
如果您正在使用,Python 3
则必须按如下方式安装:
sudo apt-get update
sudo apt-get install python3-tk
Tkinter for Python 2
(python-tk
) is different from Python 3
's (python3-tk
).
Tkinter for Python 2
( python-tk
) 与Python 3
's ( python3-tk
) 不同。
回答by Jonathan L
If you're using RHEL, CentOS, Oracle Linux, etc. You can use yum to install tkinter module
如果你使用的是 RHEL、CentOS、Oracle Linux 等,可以使用 yum 安装 tkinter 模块
yum install tkinter
回答by Arthur Kennedy Otieno Jonyo
There is _tkinter and Tkinter - both work on Py 3.x But to be safe- Download Loopy and change your python root directory(if you're using an IDE like PyCharms) to Loopy's installation directory. You'll get this library and many more.
有 _tkinter 和 Tkinter - 都在 Py 3.x 上工作,但为了安全起见 - 下载 Loopy 并将你的 python 根目录(如果你使用像 PyCharms 这样的 IDE)更改为 Loopy 的安装目录。你会得到这个库以及更多。
回答by yermama
For Arch Linux users, it goes a bit like
对于 Arch Linux 用户,它有点像
sudo pacman -S tk