【问题标题】:how to install python3-tk in centos?如何在centos中安装python3-tk?
【发布时间】:2017-03-28 01:44:32
【问题描述】:

我需要安装 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 ~]$ 

但它不起作用。

我该如何解决?

编辑: 从 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 ~]$ 

【问题讨论】:

  • 为你的 python 3.4 安装和使用 python-pip。
  • 我已经尝试从 pip 安装,但它不起作用。什么是正确的命令?
  • 大多数 Linux 都使用 Python 安装了 tk,因此您不必安装。你在 Python 中检查了import tkinter 吗?

标签: python matplotlib tkinter centos


【解决方案1】:

tkinter 在 coreos 中以 tkinter 包的形式提供。您可以使用

安装它
sudo yum install tkinter

完成后,您可以像往常一样导入和使用它。

>>> import tkinter
>>> tkinter._test()

对于 Python 3,您可以使用安装它

sudo yum install python3-tkinter

正如一些用户提到的,它可以作为python36u-tkinterpython34-tkinter 使用,具体取决于操作系统。

sudo yum install python34-tkinter
sudo yum install python36u-tkinter

【讨论】:

  • 当我尝试 Python 脚本时,它为什么会抛出错误?没有可用的包 python3-tkinter。错误:无事可做
  • 您使用的是哪个版本的操作系统?
  • 我在 RedHat 7.4 上,sudo yum install python3-tkinter 返回No package python3-tkinter available.
  • 默认的python版本是哪个? python34-tkinterpython36u-tkinter 包可用吗?
【解决方案2】:

在 Centos 7 中你可以使用:

yum install python36-tkinter

【讨论】:

    【解决方案3】:

    我使用这两个命令 100% 解决了同样的问题

    sudo yum -y update
    sudo yum -y install python36u-tkinter
    

    【讨论】:

      【解决方案4】:

      试试下面的命令。

      sudo yum install python3-tkinter
      

      现在在您的终端中测试:

      >>> import tkinter
      >>> tkinter._test()
      

      【讨论】:

        【解决方案5】:

        我相信 tk 默认带有 python。如果是这样,您是否希望重新安装您的 python 3.4。 (我更喜欢ver3.5)。此website 中提到了程序。

        步骤:

        1. 下载python版本

          wgethttps://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz

        2. 如果没有,请安装解码工具:sudo yum install xz-libs

        3. 解码xz编码xz -d Python-3.5.3.tar.xz
        4. 解压解码文件tar -xvf Python-3.5.3.tar
        5. 移动想要安装python的目录cd Python-3.5.3
        6. 配置python文件./configure
        7. 使用make 构建
        8. 使用make altinstall安装
        9. 检查 tkinter 是否工作。应该会弹出一个 tk 窗口。打开终端并输入以下内容:

        python3.5 import tkinter as tk root = tk.Tk()

        该网站还有其他安装setuptoolspip 的说明非常有用。

        【讨论】:

          【解决方案6】:

          我在这个问题上花了很多时间,这是我的有效解决方案:

          1. yum -y install tkinter tcl-devel tk-devel

          2. 到你的 python 目录: vim ......./Python3.5.1/Modules/Setup.dist

          从这些行中删除 cmets:

          _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.

          ./configure
          make && make install
          

          结果:

          [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
          >>> 
          

          【讨论】:

            【解决方案7】:

            这取决于你的 python 版本。对于 python 3.4,它是 sudo yum install python34-tkinter

            【讨论】:

              【解决方案8】:

              或者,也许您正在使用software collections (SCL),然后安装正确的 tkinter。

              搜索 tkinter: yum search tkinter
              安装适当的 tkinter,例如 yum install rh-python36-python-tkinter

              根据您用于 python 的存储库,您有不同的“默认”tkinter。

              【讨论】:

                【解决方案9】:

                我在这里尝试了所有其他解决方案,但没有一个对我有用。 经过一番研究,我找到了适合我的正确软件包。

                sudo yum update
                sudo yum install rh-python36-python-tkinter
                

                如果你使用不同版本的 python3 尝试像我一样搜索你的包

                sudo yum search tkinter
                

                看看哪个选项适合您的版本

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2019-09-06
                  • 2018-04-29
                  • 2016-05-02
                  • 1970-01-01
                  • 2019-08-06
                  • 2018-02-18
                  • 2016-08-01
                  • 2021-02-04
                  相关资源
                  最近更新 更多