问题
I'm trying to learn how to use py2app in order to create a simple Mac app from a tkinter GUI and am encountering a runtime error when attempting to do so. My Mac is running OS Catalina 10.15.4. I'm using PyCharm 2020.1 with Python 3.7. My original python installation was done using Anaconda and after trying two IDEs (Spyder and IDLE), I switched to PyCharm.
To keep things simple, the app will merely compute the sum of two user-input numbers:
from tkinter import Tk, Label, Button,Entry
window = Tk()
window.title("Sum Calculator")
window.geometry('600x300')
lbl1 = Label(window, text="First Number")
lbl1.grid(row=0,column=0)
txt1 = Entry(window,width=10)
txt1.grid(row=0,column=1)
lbl2 = Label(window, text="Second Number")
lbl2.grid(row=1,column=0)
txt2 = Entry(window,width=10)
txt2.grid(row=1,column=1)
lbl_sum=Label(window, text="Sum:")
lbl_sum.grid(row=2,column=0)
def clicked():
res="Sum= "+str(float(txt1.get())+float(txt2.get()))
lbl_sum.configure(text= res)
btn = Button(window, text="Compute", command=clicked)
btn.grid(row=3,column=0)
window.mainloop()
This file, named "tkinter_sum_calculator.py" works fine and I'm able to run the resulting Unix executable from the terminal.
Now I try to create the app using py2app following the documentation directions at https://py2app.readthedocs.io/en/latest/tutorial.html#create-a-setup-py-file
My setup.py file is as follows:
from setuptools import setup
APP = ['tkinter_sum_calculator.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Both setup.py and tkinter_sum_calculator.py are located in the same directory, /Users/fishbacp/PycharmProjects/Pycharm_example/
Then the command
python setup.py py2app
seems to work okay although so much stuff appears on my screen, including numerous import warnings such as
"ImportError in sip recipe ignored: No module named matplotlib-3"
I also ran setup.py py2app -A
although I'm still not sure what this actually does. Within the Pycharm_example directory, two new directories, "build" and "dist" are created and tkinter_sum_calculator.app is in the second of these.
However, when I attempt to run the app in the terminal I obtain the error message, "A Python runtime not could be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file."
The same runtime error results if I simply double-click the app.
I observed that the "build" folder had one directory libpython3.4.9-x86_64\python3.7-standalone\app, within which there were four empty folders collect, Frameworks, temp, libdynload
Am I missing a basic idea here that somehow a full version of Python needs to appear within the "buid" directory in order to create a stand along application? If that's the case, what would be the most direct way to accomplish this?
来源:https://stackoverflow.com/questions/61595940/python-runtime-cannot-be-located-for-app-created-using-tkinter-and-py2app