[英]How do I turn a .py file into an application on Mac?
[我知道这个问题已被问过多次,但我仍然无法找到适合我的选项]
我正在使用 replit.com 编写我的 python 代码。
我用 python 制作了一个程序,但我想把它变成一个可执行的应用程序(而不是像我在 mac 上那样的 .exe)。 我看到很多人使用 py2app 但它对我不起作用(可能是因为我使用的是在线 IDE)。 我也尝试过 PyCharm,但是当我写:“pip install py2app”来导入包时,它只是说它不知道命令“pip”。
文件名是:“main.py”
这是我的代码,以防它有帮助(它非常混乱和混乱):
from tkinter import *
import math
root = Tk()
root.title('Minion Profit Calculator')
#Variables#
money = 0
actionT = 0
itemPerAc = 0
unitPr = 0
hasDia = IntVar()
diaSprMoney = 0
money1h = 0
#Labels#
acTime = Label(root, text="Action Time:")
itemAc = Label(root, text="Item/Action:")
unitPrice = Label(root, text="Unit Price:")
diaSpread = Label(root, text="Diamond Spreading:")
profitDis = Label(root, text="Profit (/24h):")
profit = Label(root, text="")
profit1Dis = Label(root, text="Profit (/1h)")
profit1 = Label(root, text="")
#Input Fields#
acTimeIn = Entry(root)
itemAcIn = Entry(root)
unitPriceIn = Entry(root)
#Checkboxes#
diaSpreadBox = Checkbutton(root, variable=hasDia, onvalue=1, offvalue=0)
#Click Event#
def isClicked():
actionT = float(acTimeIn.get())
itemPerAc = float(itemAcIn.get())
unitPr = float(unitPriceIn.get())
money = (86400/actionT*itemPerAc*unitPr)
diaSprMoney = (138240/actionT)
if (hasDia.get() == 1):
money = money + diaSprMoney
money = math.trunc(money)
money1h = (money / 24)
money1h = math.trunc(money1h)
#Add $ before the number
money = str(money)
money1h = str(money1h)
money = ("$"+money)
money1h = ("$"+money1h)
profit.configure(text=money)
profit1.configure(text=money1h)
#Buttons#
cal = Button(root, text="Calculate", command=isClicked)
#Grid Placing#
acTime.grid(row = 0, column = 0)
itemAc.grid(row = 1, column = 0)
unitPrice.grid(row = 2, column = 0)
diaSpread.grid(row=3, column = 0)
profitDis.grid(row=5)
profit.grid(row=5, column=1)
profit1Dis.grid(row=6)
profit1.grid(row=6, column=1)
acTimeIn.grid(row=0, column=1)
itemAcIn.grid(row=1, column=1)
unitPriceIn.grid(row=2, column=1)
diaSpreadBox.grid(row=3, column=1)
cal.grid(row=4, columnspan=2)
root.mainloop
请尝试将您的代码移动到您机器上的新 python 文件中。 我认为使用 replit 不可能做到这一点。
您必须下载 pip 才能正确执行此操作。 你可以 在这里下载 pip。
下载 pip 后,您可以使用Pyinstaller库将 Python 程序打包为独立的可执行文件。 它适用于 Windows、Linux 和 Mac。
阅读此答案以获取更多详细信息。
如果您想坚持使用py2app
,只需在下载pip install py2app
在终端中运行pip install py2app
即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.