How to make code in Python to execute exe software

Convert Python program (.py) to Windows executable file (.exe)


Step 1: install pyinstaller


Open cmd, enter pip install pyinstaller

pip install pyinstaller
  • 1

Insert picture description here


Maybe due to network problems, the download will time out.


Solution:
①[download on github][(https://github.com/pyinstaller/pyinstaller)]
②Then unzip to the python installation directory, click pyinstaller-develop after the unzip is complete [the file name here may be Different, no effect on the result], open cmd in the directory to install, the installation syntax is: python setup.py install

python setup.py install
  • 1

Insert picture description here


Step 2: Convert .py to .exe


Move the written .py file to the pyinstaller-develop file, then open cmd in the current directory, and then use the command: python pyinstaller.py -F check_port.py

python pyinstaller.py -F check_port.py
  • 1

Encapsulation
Insert picture description here
packaging is finished
Insert picture description here
the last complete package can be seen, and the reciprocal (.exe) saved position of the line is an executable file

We can see the file we want by opening the path just prompted
Insert picture description here



PS: Sometimes the exe will flash back after opening, this may be because it automatically closed after executing the program. At this time, you only need to add a line of code to the end of the program.

Format:
import os

try: executed code

finally: os.system(“pause”)

os.system("pause") 
  • 1

#Can make the code pause after execution, so that we can get the data obtained by running

Guess you like

Origin blog.csdn.net/woaisjm/article/details/112815813