将.py(Python)文件转换为可执行文件(Python 3.x)时出现问题



我使用python 3编码了一个桌面应用程序,它是一个API数据收集应用程序。当我创建可执行文件(.exe(时,它在我的计算机上运行得很好,但当我在其他计算机上打开它时,我会得到

无法执行脚本消息。

代码我只导入以下内容。

from tkinter import*
import requests
import json 

然后我添加了API,如下所示。

try:
#Connect the API to the .py code
api_data=requests.get("https://www.hpb.health.gov.lk/api/get-current-statistical")
api_json=json.loads(api_data.content)
#Connect with variables
lu_date= api_json['data']['update_date_time']
lu_cases= api_json['data']['local_new_cases']
lu_total= api_json['data']['local_total_cases']
lu_hospital= api_json['data']['local_total_number_of_individuals_in_hospitals']
lu_deaths= api_json['data']['local_deaths']
lu_recover= api_json['data']['local_recovered']
lu_rate1=int((lu_deaths/lu_recover)*100)
#Added some labels here
#Button
ext_btn=Button(root, text="Exit", command=root.destroy,bg="red",fg="white",font="Helvatica 12 bold",padx=25)
ext_btn.grid(row=8,column=0,columnspan=2)
out = out.decode(encoding)
except Exception as e:
api_json="Error"
root.mainloop()

我已经尝试了以下方法来执行它,但它不起作用。(通过使用命令行和给定的GUI软件(

pyinstaller -F codename.py

经过这么多的研究和指导,我能够找到这个问题。谢谢@Bryan Oakley的指导。问题这是一个Tkinter问题,通过删除图标导入(窗口左上角的图标(,我可以解决这个问题。

#root.iconbitmap('icon.ico')

此外,我添加了一个可靠的异常处理语句。

最新更新