[英]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.