.py文件->.exe 文件 转换脚本(实用)
使用之前
请确保在使用该脚本之前安装了如下python包:
1.pyinstaller
2.pywin32
若未安装,请使用Win+R键打开“运行”,并输入cmd打开控制台
分别输入 pip install pyinstaller 和 pip install pywin32,pip会自动安装,等待安装完毕即可
另外,截止到现在,python3.7版本使用不了pyinstaller,请使用3.6及更早版本
功能:
1.将此脚本移至与待转换.py文件目录下,使用此脚本即可。或者可以运用此脚本将此文件转换成可执行文件(.exe)更好用。为了简化输入,此脚本会列出该目录下所有.py文件,每个.py文件前都有一个序列号,输入序列号即可开启转换。
2.或者还可以像控制台一样使用cd来转换目录
3.退出请输入exit
代码如下:
import time
def Console():
import os
Path = os.path.abspath('')
files = os.listdir(Path)
count = 0 # 用于循环计数
Log = {} # 记录当前目录下.py文件的字典
isChanged = True
while True:
if isChanged == True:
print(" >", Path, "\nThere have some .py files:")
for file in files:
if file.endswith('.py'):
Log[count] = file
print("%d .%s" % (count, file))
count += 1
count = 0
isChanged = False
Name = input('Command(FileName or cd or exit):\n> ')
if Name == 'exit':
print('\nAll Clear!')
break
if Name.startswith('cd '):
Name = Name[3:]
Path = Name
files = os.listdir(Path)
isChanged = True
continue
try:
Name = int(Name)
Name = Log[Name]
except:
pass
cmd = '''cd %s &\
pyinstaller.exe --onefile %s &\
''' % (Path, Name)
info = os.popen(cmd, mode='w')
info.close()
# info=info.read()
print(info)
ex = input("Press any key to exit")
if __name__ == '__main__':
Console()