Python 没有名为Tkinter的模块

Python 没有名为Tkinter的模块,python,python-2.7,pyinstaller,Python,Python 2.7,Pyinstaller,我在python2.7中有一个小脚本,我想将其转换为Windows可执行文件。为此,我使用pyinstaller 剧本: import sys import matplotlib.pyplot as plt import matplotlib.image as mpimg def get_inputs(): coor = raw_input(">>>top x left: ").replace(" ", "") top, left = coor.split

我在python2.7中有一个小脚本,我想将其转换为Windows可执行文件。为此,我使用
pyinstaller

剧本:

import sys 
import matplotlib.pyplot as plt
import matplotlib.image as mpimg


def get_inputs():
    coor = raw_input(">>>top x left: ").replace(" ", "")
    top, left = coor.split("x")
    top = int(top.strip())
    left = int(left.strip())
    return top, left 

def plot_location(top, left):
    img= mpimg.imread('nbahalfcourt.jpg')
    plt.imshow(img)
    plt.scatter(left, top)
    plt.grid()
    plt.show()

def main():
    top, left = get_inputs()
    plot_location(top, left)

if __name__ == '__main__':

    print "Input top x left coordinates (no space) eg: 44x232"

    run = True 
    while run:
        main()
基本上,脚本只是在网格上绘制一个点

转换过程成功完成。然而,当我运行.exe时,我得到了
importorror
(见下文),尽管我在任何地方都没有引用
Tkinter


这里出了什么问题?

我感觉
matplotlib
在内部使用
Tkinter
模块,但以非标准方式导入它。然后
pyinstaller
没有注意到需要Tkinter,随后也没有将其捆绑到可执行文件中


尝试显式地将
import Tkinter
放在脚本的顶部。

我遇到了同样的问题,这里的解决方案都不起作用。我当时使用的是Pyinstaller 3.2(当时的最新版本),当我使用

pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
这似乎表明,在写这篇文章时,这个问题的所有纠结仍在解决中


编辑:截至2017年1月15日,Pyinstaller版本3.2.1发布。我现在使用它,它解决了这个问题以及其他类似的问题,而我以前只能通过使用开发人员版本来解决这个问题。因此,如果您还没有升级到最新版本,我强烈建议您升级到最新版本。

我感觉
matplotlib
在内部使用
Tkinter
模块,但以非标准方式导入它。然后
pyinstaller
没有注意到需要Tkinter,随后也没有将其捆绑到可执行文件中。我想知道在脚本顶部显式地放置
import Tkinter
是否会有帮助?这就成功了!谢谢你,伙计。如果您愿意,可以将其作为答案发布,这样我就可以记录在案了。显式导入它们,这样
pyinstaller
肯定可以看到它们是一个非常好的解决方案,还有一个命令行标志,用于显式告诉
pyinstaller
包含额外的模块
--hidden import=Tkinter
,只用于记录,我必须
importfiledialog
和Tkinter导入一起进行。是的,这对我很有效。还使用3.2并获取Tkinter的导入错误。安装最新的开发者版本解决了这个问题,谢谢。对我来说,使用3.3开发版本是解决这个问题的唯一方法,谢谢