Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named Tkinter

I have a small script in python2.7 that I want to convert into Windows executable. I use pyinstaller for this.

The script:

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()

Basically, the script just plots a point on a grid.

The converting process finishes successfully. When I run the .exe however I've got the ImportError (see below) even though I have no reference to Tkinter anywhere.

enter image description here

What could went wrong here?

like image 371
nutship Avatar asked Feb 12 '23 20:02

nutship


1 Answers

I have a feeling that matplotlib uses the Tkinter module internally, but imports it in a non-standard way. Then pyinstaller doesn't notice Tkinter is needed, and subsequently doesn't bundle it into the executable.

Try explicitly putting import Tkinter at the top of your script.

like image 100
Kevin Avatar answered Feb 14 '23 12:02

Kevin