0

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.

Jonathan
  • 2,565
  • 4
  • 18
  • 25
  • 2
    in python3, Tkinter was renamed tkinter. – Bryan Oakley Jan 03 '17 at 20:22
  • @BryanOakley but this question is tagged `python-2.7`. You also have to install the Python module, which can be done via Pip. Run `pip install tkinter` at the command line. – Mat Jones Jan 03 '17 at 21:34
  • yeah, but it looks like pyinstaller is picking python 3: `30 INFO: Python: 3.4.3` And I don't think you can install tkinter with pip. – Bryan Oakley Jan 03 '17 at 21:59
  • @BryanOakley I want to use python2.7 Tkinter module, so I need to get pyinstaller to use python2.7 instead of python3.4? – Jonathan Jan 04 '17 at 01:05
  • `pyinstaller` is written in Python so you can open it in editor and see how it works. Mine has first line `#!/usr/bin/python3.5`. On Linux to find it I can use `which pyinstaller` - maybe it will work on Mac too. You can also try `python -m PyInstaller` (with upper `P` and `I`) if you have installed version for Python 2. – furas Jan 04 '17 at 02:14
  • Possible duplicate of [Which tkinter modules were renamed in Python 3?](https://stackoverflow.com/questions/673174/which-tkinter-modules-were-renamed-in-python-3) – Stevoisiak Mar 30 '18 at 19:30

1 Answers1

1

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

Jonathan
  • 2,565
  • 4
  • 18
  • 25