darrenvba
darrenvba

Reputation: 221

Pyinstaller, .py version works, .exe "No module named Tkinter"?

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

Upvotes: 0

Views: 1522

Answers (1)

Preston Hager
Preston Hager

Reputation: 1611

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.

Upvotes: 1

Related Questions