0

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?

3
  • Don't use pip to install tkinter. I guess that should be possible using brew, howeve, not sure. Python 3.7 definetly does support tkinter, but pip is unable to install it.
    – rizerphe
    May 7, 2020 at 15:50
  • Thanks for the clarification regarding the 3.7 support. I don't know exactly how the app operates when executed, but could my OS be trying to run the app using an old version of Python?
    – fishbacp
    May 7, 2020 at 17:21
  • I don't think so since you have said that you've tried to install it with pip.
    – rizerphe
    May 7, 2020 at 17:24

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.