{"id":1622,"date":"2023-08-02T15:48:13","date_gmt":"2023-08-02T07:48:13","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=1622"},"modified":"2023-08-02T15:48:13","modified_gmt":"2023-08-02T07:48:13","slug":"gui%e6%89%93%e5%8c%85%e6%88%90exe%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/1622\/","title":{"rendered":"gui\u6253\u5305\u6210exe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"

\u5728Python\u4e2d\uff0cGUI\u7a0b\u5e8f\u7684\u5f00\u53d1\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u4e0d\u540c\u7684\u6846\u67b6\uff0c\u5982Tkinter\u3001Py\u6587\u4ef6\u5939\u5c01\u88c5exe<\/a>Qt\u3001wxPython\u7b49\u3002\u800c\u6253\u5305GUI\u7a0b\u5e8f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\u5219\u662f\u5c06Python\u4ee3\u7801\u548c\u76f8\u5173\u5e93\u3001\u8d44\u6e90\u6587\u4ef6\u7b49\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n

\u6253\u5305GUI\u7a0b\u5e8f\u6210exe\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5de5\u5177\uff0c\u5982pyinstaller\u3001cx_Freeze\u3001py2exe\u7b49\u3002\u4e0b\u9762\u4ee5pyinstaller\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u6253\u5305GUI\u7a0b\u5e8f\u6210exe\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

### \u539f\u7406<\/p>\n

\u6253\u5305GUI\u7a0b\u5e8f\u6210exe\u7684\u672c\u8d28\u662f\u5c06Python\u4ee3\u7801\u548c\u76f8\u5173\u5e93\u3001\u8d44\u6e90\u6587\u4ef6\u7b49\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u5c06Python\u89e3\u91ca\u5668\u5d4c\u5165\u5176\u4e2d\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709<\/p>\n

<\/figure>\n<\/p>\n

Python\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u8fd0\u884c\u7a0b\u5e8f\u3002\u5177\u4f53\u6765\u8bf4\uff0cpyinstaller\u7684\u6253\u5305\u8fc7\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n

1. \u89e3\u6790Python\u4ee3\u7801\u548c\u4f9d\u8d56\u5e93\uff1apyinstaller\u4f1a\u89e3\u6790Python\u4ee3\u7801\u548c\u4f9d\u8d56\u5e93\u4e2d\u7684import\u8bed\u53e5\uff0c\u627e\u51fa\u6240\u6709\u9700\u8981\u6253\u5305\u7684\u6a21\u5757\u548c\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n

2. \u751f\u6210spec\u6587\u4ef6\uff1apyinstaller\u4f1a\u6839\u636e\u89e3\u6790\u7ed3\u679c\u751f\u6210\u4e00\u4e2aspec\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u9700\u8981\u6253\u5305\u7684\u6a21\u5757\u548c\u8d44\u6e90\u6587\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n

3. \u6253\u5305Python\u89e3\u91ca\u5668\uff1apyinstaller\u4f1a\u5c06Python\u89e3\u91ca\u5668\u548c\u4f9d\u8d56\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u6587\u4ef6\u5939\u3002<\/p>\n

4. \u6253\u5305\u53ef\u6267\u884c\u6587\u4ef6\uff1apyinstaller\u4f1a\u5c06Python\u4ee3\u7801\u548c\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86Python\u89e3\u91ca\u5668\u548c\u4f9d\u8d56\u5e93\u3002<\/p>\n

### \u6b65\u9aa4<\/p>\n

\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528pyinstaller\u6253\u5305GUI\u7a0b\u5e8f\u6210exe\u7684\u6b65\u9aa4\u3002<\/p>\n

1. \u5b89\u88c5pyinstaller<\/p>\n

\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5pyinstaller\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

2. \u7f16\u5199Python\u4ee3\u7801<\/p>\n

\u7f16\u5199GUI\u7a0b\u5e8f\u7684Python\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u4e00\u4e2aGUI\u6846\u67b6\u3002<\/p>\n

3. \u751f\u6210spec\u6587\u4ef6<\/p>\n

\u4f7f\u7528pyinstaller\u751f\u6210spec\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u9700\u8981\u6253\u5305\u7684\u6a21\u5757\u548c\u8d44\u6e90\u6587\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n

“`<\/p>\n

pyinstaller –name=myapp –windowed –onefile myapp.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c–name\u6307\u5b9a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u540d\u79f0\uff0c–windowed\u6307\u7528html\u5f00\u53d1exe<\/a>\u5b9a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u662f\u5426\u4e3a\u7a97\u53e3\u6a21\u5f0f\uff0c–onefile\u6307\u5b9a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u662f\u5426\u4e3a\u5355\u6587\u4ef6\u6a21\u5f0f\u3002<\/p>\n

4. \u6253\u5305\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u4f7f\u7528pyinstaller\u6253\u5305Python\u4ee3\u7801\u548c\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

“`<\/p>\n

pyinstaller myapp.spec<\/p>\n

“`<\/p>\n

\u6253\u5305\u5b8c\u6210\u540e\uff0c\u53ef\u6267\u884c\u6587\u4ef6\u4f1a\u751f\u6210\u5728dist\u76ee\u5f55\u4e0b\u3002<\/p>\n

\u603b\u4e4b\uff0c\u6253\u5305GUI\u7a0b\u5e8f\u6210exe\u53ef\u4ee5\u8ba9\u7528\u6237\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u8fd0\u884c\u7a0b\u5e8f\uff0c\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u3002\u867d\u7136pyinstaller\u662f\u5176\u4e2d\u4e00\u79cd\u5de5\u5177\uff0c\u4f46\u662f\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\u4e5f\u662f\u7c7b\u4f3c\u7684\uff0c\u53ea\u9700\u8981\u6ce8\u610f\u4e00\u4e9b\u53c2\u6570\u7684\u4e0d\u540c\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728Python\u4e2d\uff0cGUI\u7a0b\u5e8f\u7684\u5f00\u53d1\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u4e0d\u540c\u7684\u6846\u67b6\uff0c\u5982Tkinter\u3001PyQt\u3001wxPython\u7b49\u3002\u800c\u6253\u5305GUI\u7a0b\u5e8f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\u5219\u662f\u5c06Python\u4ee3\u7801\u548c\u76f8\u5173\u5e93\u3001\u8d44\u6e90\u6587\u4ef6\u7b49\u6253\u5305\u6210\u4e00\u4e2a\u72ec<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[3537,3538,256,16,89],"topic":[],"class_list":["post-1622","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-pc","tag-uibotexe","tag-256","tag-16","tag-89"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=1622"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1622\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=1622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=1622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=1622"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=1622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}