fishbacp
fishbacp

Reputation: 1263

Unable to execute at the terminal a Mac app created using tkinter and py2app

I'm using Python 3.7 and the IDLE IDE on my Mac running Catalina 10.15.4.

I'm trying to create a simple app using tkinter and py2app. At this stage I have a simple script, heatmap.py, which uses tkinter, accepting as input a square matrix, e.g. [[1,2],[3,4]] and creating a heatplot in a new window. The file executes fine.

Moreover, if I create the file heatmap.command, by first inserting #!/usr/bin/env python3 at the top of the .py file, renaming heatmap.py to heatmap.command, and typing chmod +x heatmap.command at the terminal, the file executes fine by typing ./heatmap.command at the terminal.

So now I'm trying to create an app using py2app, following the directions at https://py2app.readthedocs.io/en/latest/tutorial.html as follows, assuming I've changed directories at the terminal to be working in the one containing heatmap.py:

py2applet --make-setup heatmap.py

rm -rf build dist

python setup.py py2app -A

This works without error messages. Within my current directory, I see a folder containing an app called heatmap. Before building for deployment (via entering python setup.py py2app), I tried to run the application at the terminal:

./dist/heatmap.app/Contents/MacOS/heatmap

This resulted in an error message indicating "tkinter could not be found."

I observed that /Library/Frameworks/Python.framework/Versions/3.7/lib/Python3.7/site-packages did not contain tkinter. However the directory one level up, /Library/Frameworks/Python.framework/Versions/3.7/lib/Python3.7, did contain it.

As a first attempt to address the message I merely copied the tkinter folder into the site-packages folder. This didn't work.

So I tried to install it again two different ways:

  1. In the terminal: pip install tkinter
  2. Using IDLE:

    a. First determine system executable path obtained in IDLE via the command sys; sys.executable, which returned '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7'

    b. Then type /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install tkinter

Method 2 is how I've installed numerous other packages using IDLE. In both cases, I received the following error message:

ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter

Does this mean 3.7 does not support tkinter? I did not think that was the case, or perhaps there's some error I'm making?

Upvotes: 0

Views: 139

Answers (1)

fishbacp
fishbacp

Reputation: 1263

I updated my OS python version from 2.7.16 to 3.7 using directions posted at

https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf

Then everything worked fine. I was also able to deploy the app and open it fine just by double-clicking heatmap.app.

Upvotes: 0

Related Questions