如何在centos中安装python3-tk?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40588444/
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
how to install python3-tk in centos?
提问by Donbeo
I need to install python3-tk in order to use matplotlib.
我需要安装 python3-tk 才能使用 matplotlib。
I have tried:
(python_3.4_numerical) [lpuggini@machinelearn-1 ~]$ sudo yum install python3-tk
[sudo] password for lpuggini:
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.clouvider.net
* epel: epel.check-update.co.uk
* extras: mirror.sov.uk.goscomb.net
* updates: mirrors.clouvider.net
No package python3-tk available.
Error: Nothing to do
(python_3.4_numerical) [lpuggini@machinelearn-1 ~]$
but it is not working.
但它不起作用。
How can I fix it?
我该如何解决?
EDIT: Installing from pip does not work:
编辑:从 pip 安装不起作用:
(python_3.4_numerical) [lpuggini@machinelearn-1 ~]$ pip install pygtk
Collecting pygtk
Using cached pygtk-2.24.0.tar.bz2
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-nzjsuhx3/pygtk/
(python_3.4_numerical) [lpuggini@machinelearn-1 ~]$
回答by ChillarAnand
tkinter is available in coreos as tkinter
package. You can install it with
tkinter 在 coreos 中作为tkinter
包提供。你可以安装它
sudo yum install tkinter
Once it is done, you can import and use it as usual.
完成后,您可以像往常一样导入和使用它。
>>> import tkinter
>>> tkinter._test()
For Python 3, you can install it with
对于 Python 3,您可以安装它
sudo yum install python3-tkinter
As some users mentioned, it is available as python36u-tkinter
or python34-tkinter
depending on OS.
正如一些用户所提到的,它可以作为python36u-tkinter
或python34-tkinter
取决于操作系统。
sudo yum install python34-tkinter
sudo yum install python36u-tkinter
回答by Rajiv Sharma
In Centos 7 you can use:
在 Centos 7 中,您可以使用:
yum install python36-tkinter
回答by javac
I solved the same problem using these two commands 100%
我使用这两个命令 100% 解决了同样的问题
sudo yum -y update
sudo yum -y install python36u-tkinter
回答by Baschdl
It depends on your python version. For python 3.4 it's sudo yum install python34-tkinter
这取决于您的python版本。对于 python 3.4,它是sudo yum install python34-tkinter
回答by MasaYan
Or, maybe you are using software collections (SCL), then install the proper tkinter.
或者,也许您正在使用软件集合 (SCL),然后安装正确的 tkinter。
search tkinter:
yum search tkinter
install proper tkinter such as
yum install rh-python36-python-tkinter
搜索 tkinter:
yum search tkinter
安装适当的 tkinter,例如
yum install rh-python36-python-tkinter
Depending on which repository you are using for python, you have different "default" tkinter.
根据您为 python 使用的存储库,您有不同的“默认”tkinter。
回答by orvi
Try the following command.
试试下面的命令。
sudo yum install python3-tkinter
Now Test in your terminal:
现在在你的终端中测试:
>>> import tkinter
>>> tkinter._test()
回答by Sun Bear
I believe tk come with python by default. If so, have you look to reinstall your python 3.4. (I prefer ver3.5). Procedures are mentioned in this website.
我相信默认情况下 tk 与 python 一起提供。如果是这样,您是否希望重新安装python 3.4。(我更喜欢 ver3.5)。本网站提到了程序。
Steps:
脚步:
Download python version
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
Install decoding tool if you don't have:
sudo yum install xz-libs
- Decode the xz encodeing
xz -d Python-3.5.3.tar.xz
- Uncompress the decoded file
tar -xvf Python-3.5.3.tar
- Move the desired directory to install python
cd Python-3.5.3
- Configure python file
./configure
- Build using
make
- Install using
make altinstall
- Check if tkinter works. A tk window should pop out. Open a terminal and type the following:
下载python版本
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
如果您没有,请安装解码工具:
sudo yum install xz-libs
- 解码 xz 编码
xz -d Python-3.5.3.tar.xz
- 解压解码文件
tar -xvf Python-3.5.3.tar
- 移动所需目录安装python
cd Python-3.5.3
- 配置python文件
./configure
- 构建使用
make
- 安装使用
make altinstall
- 检查 tkinter 是否有效。应该会弹出一个 tk 窗口。打开终端并键入以下内容:
python3.5
import tkinter as tk
root = tk.Tk()
python3.5
import tkinter as tk
root = tk.Tk()
The website also has other instructions for installing setuptools
and pip
which are very useful.
该网站还有其他安装说明setuptools
,pip
这些说明非常有用。
回答by Dabney J
I spent lots of time on this problem, here is my solution effectively:
我在这个问题上花了很多时间,这是我的有效解决方案:
yum -y install tkinter tcl-devel tk-devel
to your python directory:
vim ......./Python3.5.1/Modules/Setup.dist
yum -y install tkinter tcl-devel tk-devel
到你的python目录:
vim ......./Python3.5.1/Modules/Setup.dist
Remove comments from these lines:
从这些行中删除注释:
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-ltk8.5 -ltcl8.5 \ # default is 8.2 and you should change it to the version you installed in step1
-lX11
3.
3.
./configure
make && make install
Result:
结果:
[root@localhost Python-3.5.1]# python3
Python 3.5.1 (default, Jun 19 2017, 22:43:42)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
回答by Guy
I tried all the other solutions here and none of them work for me. After a bit of research, I found the right package that worked for me.
我在这里尝试了所有其他解决方案,但没有一个对我有用。经过一番研究,我找到了适合我的合适的软件包。
sudo yum update
sudo yum install rh-python36-python-tkinter
if you use a different version of python3 try searching for your package as I did with
如果您使用不同版本的 python3,请尝试像我一样搜索您的包
sudo yum search tkinter
and see what option fits your version
看看哪个选项适合你的版本