【发布时间】:2018-07-15 00:44:59
【问题描述】:
我尝试使用 PyInstaller 将我的 python 程序转换为 .app。实际代码通过 IDLE 运行良好,但每次我尝试运行新转换的 .app 时,它都会立即关闭。下面是我的 .spec 文件和我的 .py 文件。我已经编辑了 .spec 文件,在我的 .py 文件中添加了我导入的文本文件。
Python 文件:
#CENTRALCOAST: 2250-2420
#CENTRALCOAST2: 2250-2267
#NORTHERNBEACHES: 2084-2108
CentralCoast = []
NorthernBeaches = []
OOR = []
Invalid = []
import math
def numLen(num):
return len(str(abs(num)))
with open('postcodes.txt') as input_file:
long_list = [line.strip() for line in input_file]
for i in range(len(long_list)):
long_list[i] = int(long_list[i])
for each in long_list:
if 2084 <= each <= 2108: #NorthernBeaches
NorthernBeaches.extend([each])
for each in long_list:
if 2250 <= each <= 2267: #CentralCoast
CentralCoast.extend([each])
for each in long_list:
if not 2250 <= each <= 2267:
OOR.extend([each])
#for each in long_list:
# if numLen(each) != 4:
# Invalid.extend([each])
Total = len(CentralCoast) + len(OOR) + len(NorthernBeaches) + len(Invalid)
print("Central Coast:", len(CentralCoast), "------", round(len(CentralCoast)/Total,2), "%")
print("")
print("Northern Beaches:", len(NorthernBeaches), "------", round(len(NorthernBeaches)/Total,4), "%")
print("")
print("Out of Range:", len(OOR), "------", round(len(OOR)/Total,2), "%")
print("")
#i = 0
#for i in OOR:
# print(i)
# i = i + 1
print("Invalid Entry:", len(Invalid), "------", round(len(Invalid)/Total,4), "%")
print("")
print("")
print("Total:", Total)
exit = input("")
规格文件:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['algorithmPOSTCODE.py'],
pathex=['/Users/CooperTimewell'],
binaries=[],
datas=[('postcodes.txt', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='algorithmPOSTCODE',
debug=False,
strip=False,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='algorithmPOSTCODE')
app = BUNDLE(coll,
name='algorithmPOSTCODE.app',
icon=None,
bundle_identifier=None)
如何阻止它立即关闭?谢谢。
【问题讨论】:
-
@MitaleeRao 你指的是同一个页面
标签: python pyinstaller