PythonC API 3.8.0参考手册pdf下载
°²×°
pip insatll Pyinstaller
²ÎÊý
pyinstaller -Fw main.py
²ÎÊý | ¸ÅÊö |
---|---|
-F,-onefile | ´ò°üÒ»¸öµ¥¸öÎļþ£¬Èç¹ûÄãµÄ´úÂ붼дÔÚÒ»¸ö.pyÎļþµÄ»°£¬¿ÉÒÔÓÃÕâ¸ö£¬Èç¹ûÊǶà¸ö.pyÎļþ¾Í±ðÓà |
-D, ¨Conedir | ´ò°ü¶à¸öÎļþ£¬ÔÚdistÖÐÉú³ÉºÜ¶àÒÀÀµÎļþ£¬ÊʺÏÒÔ¿ò¼ÜÐÎʽ±àд¹¤¾ß´úÂ룬ÎÒ¸öÈ˱ȽÏÍƼöÕâÑù£¬´úÂëÒ×ÓÚά»¤ |
-K, ¨Ctk | ÔÚ²¿Êðʱ°üº¬ TCL/TK |
-a, ¨Cascii | ²»°üº¬±àÂë.ÔÚÖ§³ÖUnicodeµÄpython°æ±¾ÉÏĬÈÏ°üº¬ËùÓеıàÂë. |
-d, ¨Cdebug | ²úÉúdebug°æ±¾µÄ¿ÉÖ´ÐÐÎļþ |
-w,¨Cwindowed,¨Cnoconsole | ʹÓÃWindows×ÓϵͳִÐÐ.µ±³ÌÐòÆô¶¯µÄʱºò²»»á´ò¿ªÃüÁîÐÐ(Ö»¶ÔWindowsÓÐЧ) |
-s,¨Cstrip | ¿ÉÖ´ÐÐÎļþºÍ¹²Ïí¿â½«run through strip.×¢ÒâCygwinµÄstripÍùÍùʹÆÕͨµÄwin32 DllÎÞ·¨Ê¹ÓÃ. |
-X, ¨Cupx | Èç¹ûÓÐUPX°²×°(Ö´ÐÐConfigure.pyʱ¼ì²â),»áѹËõÖ´ÐÐÎļþ(WindowsϵͳÖеÄDLLÒ²»á)(²Î¼ûnote) |
-o DIR, ¨Cout=DIR | Ö¸¶¨specÎļþµÄÉú³ÉĿ¼,Èç¹ûûÓÐÖ¸¶¨,¶øÇÒµ±Ç°Ä¿Â¼ÊÇPyInstallerµÄ¸ùĿ¼,»á×Ô¶¯´´½¨Ò»¸öÓÃÓÚÊä³ö(specºÍÉú³ÉµÄ¿ÉÖ´ÐÐÎļþ)µÄĿ¼.Èç¹ûûÓÐÖ¸¶¨,¶øµ±Ç°Ä¿Â¼²»ÊÇPyInstallerµÄ¸ùĿ¼,Ôò»áÊä³öµ½µ±Ç°µÄĿ¼ÏÂ. |
-p DIR, ¨Cpath=DIR | ÉèÖõ¼Èë·¾¶(ºÍʹÓÃPYTHONPATHЧ¹ûÏàËÆ).¿ÉÒÔÓ÷¾¶·Ö¸î·û(WindowsʹÓ÷ֺÅ,LinuxʹÓÃðºÅ)·Ö¸î,Ö¸¶¨¶à¸öĿ¼.Ò²¿ÉÒÔʹÓöà¸ö-p²ÎÊýÀ´ÉèÖöà¸öµ¼Èë·¾¶£¬ÈÃpyinstaller×Ô¼ºÈ¥ÕÒ³ÌÐòÐèÒªµÄ×ÊÔ´ |
¨Cicon=<FILE.ICO> | ½«file.icoÌí¼ÓΪ¿ÉÖ´ÐÐÎļþµÄ×ÊÔ´(Ö»¶ÔWindowsϵͳÓÐЧ)£¬¸Ä±ä³ÌÐòµÄͼ±ê pyinstaller -i ico·¾¶ xxxxx.py |
-v FILE, ¨Cversion=FILE | ½«verfile×÷Ϊ¿ÉÖ´ÐÐÎļþµÄ°æ±¾×ÊÔ´(Ö»¶ÔWindowsϵͳÓÐЧ) |
-n NAME, ¨Cname=NAME | ¿ÉÑ¡µÄÏîÄ¿(²úÉúµÄspecµÄ)Ãû×Ö.Èç¹ûÊ¡ÂÔ,µÚÒ»¸ö½Å±¾µÄÖ÷ÎļþÃû½«×÷ΪspecµÄÃû×Ö |
×¢ÒâÊÂÏî
- Èç¹û³ÌÐòÓвÉÓÃÍⲿÎļþ£¬ÈçÅäÖÃÎļþ£¬ ÐèÒª½«Îļþ·ÅÔÚdistÖÐ
- -F ÊʺÏÉú³ÉÒ»¸öµ¥Ò»¿ÉÖ´ÐеÄÎļþ
- -o ÊÊÓÃÓÚ¶à¸öÎļþÒýÓÃÇé¿ö£¬»òÕß¿ò¼ÜµÄ½á¹¹
´ò°ü½ø³ÌÏà¹Ø´úÂëʧ°Ü
ÀýÈç±àдһЩ½ø³ÌÏà¹ØµÄshellÃüÁ´ò°üʧ°Ü£¬Ò»°ãÊÇʹÓà -F ¿ÉÒԳɹ¦£¬µ«ÊÇÖ´ÐÐexeʱÓÐcmdµ¯´°£¬Õâ·Ç³£²»ÃÀ¹Û£¬ Èç¹ûʹÓÃ-Fw c²ÎÊýÖ´ÐÐexe Ö±½Óʧ°Ü¡£ ÕâÖÖÇé¿öÓÐÁ½ÖÖ½â¾ö·½°¸¡£
·½°¸Ò»£º ʹÓà pyinstaller -Dw file.py Éú³ÉµÄÊÇÒ»¸öĿ¼Îļþ¡£ ³ÌÐòÖ´Ðгɹ¦£¬ÎÞºÚÃûÖն˵¯´°Çé¿ö¡£
·½°¸¶þ£º ÆðÓà os.popen() ·½·¨£¬ ¸ÄÓÃsubprocess.Popen() Ä£¿é
ÏÂÃæÊÇÎҵIJâÊÔ£¬Çײâ³É¹¦£¬ ²ÎÊýÒ»¶¨ÒªÅäÖú㬷ñÔò³ÌÐòÖ´ÐÐʧ°Ü£¡
import subprocess def checkprocess(): processnames = ['EXCEL.EXE'] for processname in processnames: p = subprocess.Popen('taskkill /F /IM %s' %processname,shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) p.wait() checkprocess()
ÓпÕдһ¸ö ¹ØÓÚsubprocessµÄ½Ì³Ì£¬ÏêϸÑо¿Ò»ÏÂËûµÄ²ÎÊýÅäÖÃ
¹¤ÓûÉÆÆäÊ£¬±ØÏÈÀûÆäÆ÷£¡
ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íû¶Ô´ó¼ÒµÄѧϰÓÐËù°ïÖú£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö½Å±¾Ö®¼Ò¡£
转载请注明:谷谷点程序 » Pyinstaller 打包exe教程及问题解决