程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[reprint] Python packages exe files and hides the CMD command window

編輯:Python

Original article
Virtual environment installation pyinstaller

pip install pyinstaller

pack exe command :( There are a lot of specific orders online )

# pack 1 individual py file , And hide the execution window 
pyinstaller -F -w main.py
# pack 1 individual py file (-F), And hide the execution window (-w), Replace exe Of ico Icon (-i img.ico)
pyinstaller -F -w -i img.ico main.py

The above packaging method will save various dependent libraries to folders as source files , Most of the time we still want only one exe file

Package all dependent libraries in the folder into exe Inside :

# Merge into one exe Inside (--onefile), Replace exe Icon (--icon=img.ico),py Source file (main.py), Hide execution (-w)
pyinstaller --onefile --icon=img.ico main.py -w

Be careful : When all dependent libraries are packaged into one exe in the future , And hidden in CMD There will be an error when executing in window mode , Cause the program to not work properly , So you need to use

import subprocess
cmd = ' Yours CMD command '
res = subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved