4

I'm trying to bundle my script into a .app using Tkinter as the GUI and the wrapper that does the bundling is Platypus.

I'm getting this error when I go to run the app.

Traceback (most recent call last):
File "/Users/samb/Desktop/Beta1.app/Contents/Resources/script", line 4, in <module>
  import tkinter
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/P...ework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
  import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

I'm running Python 3.7.4 on this machine, and my script uses:

import tkinter
from tkinter import filedialog

which should make it compatible. The script works when I run it using terminal, just not when I run the app.

Platypus

I've specified in the bundling app that it should use python3 as well...

Not sure what I'm doing wrong here?

srb7
  • 337
  • 2
  • 9
  • I've only just begun using tkinter but I thought it was something that come with Python? EDIT: plus it seems to run in terminal when I type python3 and the file path of the script - does that confirm tkinter is installed correctly within python3? – srb7 Sep 18 '19 at 08:43
  • You don't have to use `import _tkinter`, read [Import _tkinter or tkinter?](https://stackoverflow.com/a/48385739/7414759) – stovfl Sep 18 '19 at 14:18
  • My script isn't using ```import _tkinter``` maybe the wrapper is? – srb7 Sep 18 '19 at 15:48

1 Answers1

0

Several problems: There is no file at /usr/bin/python3. Either use /usr/local/bin/python3 or /usr/bin/env with python3 as args. Or whatever your particular python environment needs.

For some reason, python is looking for the library inside Xcode, which is unusual. I have python3 installed and there's no python in

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/

On my installation, the valid filepath is:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py

(i.e. in /Library, not inside Xcode.) As the script works in Terminal, it's likely that Platypus's config is wrong somehow.

As a quick hack, I suppose you could symlink Python.framework from /Library/Frameworks to the Frameworks folder inside Xcode.

As stated in the comments, you don't need to include the first import line. Currently, you're importing all of tkinter, and then importing just the filedialog. The whole point of from is to avoid importing the entire library.

benwiggy
  • 1,440
  • 17
  • 35