zoukankan      html  css  js  c++  java
  • import Tkinter的时候报错

    在看到图形界面编程的时候,需要导入Tkinter模块,从而在解释器中进行import Tkinter,然后。。。报错如下:

    >>> from tkinter import *
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python2.7/tkinter/__init__.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ImportError: No module named _tkinter

    从报错信息来看,就是导入的时候出错,没有找到tkinter模块,主要是由于在进行编译python的时候,没有对Tk进行做相应的配置。


    解决方案如下:

    查询操作系统中安装的tk包:

    rpm -qa|grep ^tk  #表示查询以tk开头的安装包
    在结果中,只有一个tk包安装了,从而缺少了一个tk-devel的安装包没进行安装。


    从而,需要安装tk-devel包,如下所示:(也可以使用其他的方法来进行安装,例如rpm安装,但是yum是最方便的)

    yum -y install tk-devel #安装tk-devel安装包


    安装好之后,必须进行重新编译python

    1 ./configure --prefix=/usr/local/python
    2 make && make install

    测试:直接导入模块,不出现任何错误即可。


    for linux and python
  • 相关阅读:
    CodeForces
    CodeForces
    AtCoder
    AtCoder
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    Centos7配置yum国内镜像及仓库升级
    环境变量
  • 原文地址:https://www.cnblogs.com/kellyseeme/p/5525057.html
Copyright © 2011-2022 走看看