Python .py file -.> Exe file conversion script (practical)

.py file -.> exe file conversion script (practical)

Before use

Make sure that before using the following python package installation script:
1.pyinstaller
2.pywin32
If not installed, Win + R using the key to open the "Run", and enter the open cmd console
are input pip install pyinstaller and pip install pywin32, pip install automatically, you can wait for installation
In addition, as of now, python3.7 version can not use pyinstaller, use the 3.6 and earlier versions


Function:
1. Under this script to move the file to be converted .py directory, use this script. Or you can use this script to convert the file into an executable file (.exe) easier to use. To simplify input, this script lists all .py files in that directory, before each .py file has a serial number, enter the serial number to open conversion.
2. Or you can also use the same console as to convert cd directory
3. Exit Enter exit

code is as follows:

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()
Published 19 original articles · won praise 3 · Views 6892

Guess you like

Origin blog.csdn.net/weixin_42132384/article/details/98115727