Jonathan
Jonathan

Reputation: 2653

Pyinstaller No Module Tkinter

I have created a python script using Tkinter and am trying to package it using a Mac with Pyinstaller. Pyinstaller creates the executable but when I try to run it says the Tkinter module is missing. I realize there are several similar questions like this on SO but none of the solutions have worked for me.

Here is the top of my main.py script:

#!/usr/bin/env python
import sys
import os
import traceback
import json
import time
import Tkinter

Here is my pyinstaller version:

$ pyinstaller --version
3.3.dev0+483c819

I run pyinstaller with this command:

$ pyinstaller main.py 

Here is the output of that command:

30 INFO: PyInstaller: 3.3.dev0+483c819
30 INFO: Python: 3.4.3
34 INFO: Platform: Darwin-15.6.0-x86_64-i386-64bit
35 INFO: wrote /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/main.spec
36 INFO: UPX is not available.
38 INFO: Extending PYTHONPATH with paths
['/Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container',
 '/Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container']
38 INFO: checking Analysis
38 INFO: Building Analysis because out00-Analysis.toc is non existent
38 INFO: Initializing module dependency graph...
39 INFO: Initializing module graph hooks...
40 INFO: Analyzing base_library.zip ...
1395 INFO: Processing pre-find module path hook   distutils
2445 INFO: running Analysis out00-Analysis.toc
2452 INFO: Caching module hooks...
2454 INFO: Analyzing /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/main.py
2499 INFO: Loading module hooks...
2499 INFO: Loading module hook "hook-encodings.py"...
2553 INFO: Loading module hook "hook-pydoc.py"...
2553 INFO: Loading module hook "hook-xml.py"...
2753 INFO: Loading module hook "hook-distutils.py"...
2766 INFO: Looking for ctypes DLLs
2766 INFO: Analyzing run-time hooks ...
2773 INFO: Looking for dynamic libraries
2836 INFO: Looking for eggs
2836 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.4/Python
2838 INFO: Warnings written to /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/build/main/warnmain.txt
2861 INFO: checking PYZ
2861 INFO: Building PYZ because out00-PYZ.toc is non existent
2861 INFO: Building PYZ (ZlibArchive) /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/build/main/out00-PYZ.pyz
3175 INFO: checking PKG
3176 INFO: Building PKG because out00-PKG.toc is non existent
3176 INFO: Building PKG (CArchive) out00-PKG.pkg
3185 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/bootloader/Darwin-64bit/run
3185 INFO: checking EXE
3185 INFO: Building EXE because out00-EXE.toc is non existent
3185 INFO: Building EXE from out00-EXE.toc
3185 INFO: Appending archive to EXE /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/build/main/main
3187 INFO: Fixing EXE for code signing /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/build/main/main
3192 INFO: checking COLLECT
3192 INFO: Building COLLECT because out00-COLLECT.toc is non existent
3192 INFO: Building COLLECT out00-COLLECT.toc

When I run the executable a terminal window opens with the following output:

Last login: Tue Jan  3 11:35:51 on ttys004
/Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/dist/main/main ; exit;
[11:43:24][~]$ /Users/jonathanwilson/Documents/Projects/hr_digitization_tool/hr-records-management-tool-no-container/dist/main/main ; exit;
Traceback (most recent call last):
  File "main.py", line 7, in <module>
ImportError: No module named 'Tkinter'
Failed to execute script main
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

I have tried running the pyinstaller command with --hidden-import Tkinter but that still does not work. I have checked the pyinstaller docs section "When Things Go Wrong" but still don't see a solution.

Upvotes: 0

Views: 1587

Answers (1)

Jonathan
Jonathan

Reputation: 2653

I ended up finding the problem so figured I would share. As Bryan Oakley pointed out in the question comments, pyinstaller was using python3, I needed python2 since I was using the python2 Tkinter version (and also some other python2 modules).

I did pip uninstall pyinstaller and pip3 uninstall pyinstaller to make sure I had completely removed pyinstaller. I then did pip2.7 install pyinstaller to install it for python2. Pyinstaller then correctly used python2 and loaded the Tkinter module with no issues (well I did have some issues related to my python2 not being added to my path, but that was unrelated to this issue).

Upvotes: 1

Related Questions