0

I don't understand how this happened. myscript.py works, Tkinter is installed. However once I converted it to .exe using pyinstaller, I ran myscript.exe, I got a message in command prompt saying "No module named Tkinter".

How can I fix this? I've already tried to convert it several times, tried using --noupx, and also tried reinstalling pyinstaller. Thanks

darrenvba
  • 201
  • 2
  • 5
  • 21

1 Answers1

1

PyInstaller - Hidden Imports

Try using the --hiddenimport flag. Do --hiddenimport=Tkinter, or replace the Tkinter with whatever module you need. The issue seems reoccurring throughout the PyInstaller community. Here is one article.

Name Space

Tkinter has changed its namespaces from Python 2 to Python 3. It's now named tkinter in Python 3 and Tkinter in Python 2. This is the code I like to use so it's cross-version.

try:
  import Tkinter as tk
except ImportError:
  import tkinter as tk

Then you can reference Tkinter as tk. Or if you do from Tkinter import * you can just use everything without a namespace. See the list here for more of the name changes between version.

Preston Hager
  • 1,514
  • 18
  • 33
  • Thanks but I don't think that is the issue as the script works, the problem occurs when I try to convert it to .exe – darrenvba Dec 13 '16 at 12:19
  • Made a few edits, the issue seems to be occurring with PyInstaller with most people. There are a few articles on the [PyInstaller GitHub](https://github.com/pyinstaller/pyinstaller/issues?utf8=%E2%9C%93&q=Module%20not%20Found) for this. – Preston Hager Dec 13 '16 at 12:38