{"id":6416,"date":"2023-09-26T12:18:46","date_gmt":"2023-09-26T04:18:46","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=6416"},"modified":"2023-09-26T12:18:46","modified_gmt":"2023-09-26T04:18:46","slug":"idle%e6%80%8e%e6%a0%b7%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/09\/26\/idle%e6%80%8e%e6%a0%b7%e7%94%9f%e6%88%90exe%e6%96%87%e4%bb%b6%ef%bc%9f\/","title":{"rendered":"idle\u600e\u6837\u751f\u6210exe\u6587\u4ef6\uff1f"},"content":{"rendered":"

\u5728Python\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5c06Python\u811a\u672c (.py) \u8f6c\u6362\u6210\u53ef\u6267\u884c\u6587\u4ef6 (.exe) \u4ee5\u8ba9\u5176\u4ed6\u7528\u6237\u66f4\u65b9\u4fbf\u5730\u8fd0\u884c\u7a0b\u5e8f\uff0c\u800c\u4ed6\u4eec\u53ef\u80fd\u6ca1\u6709\u5b89\u88c5Python\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u4e3a\u4f60\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyInstaller\u5e93\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8fc7\u7a0b\u3002PyInstaller\u53ef\u4ee5\u5728Windows\u3001Linux\u548cmacOS\u7b49\u591a\u4e2a\u5e73\u53f0\u4e0a\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

**\u51c6\u5907\u5de5\u4f5c**<\/p>\n

\u9996\u5148\uff0c\u8bf7\u786e\u4fdd\u5df2\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86Python\u3002\u5728\u5b89\u88c5\u5b8cPython\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5PyInstaller\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528PIP\u5b89\u88c5\uff1a<\/p>\n

“`sh<\/p>\n

\u524d\u7aef\u6253\u5305exe\u5de5\u5177<\/a><\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

\u8bf7\u786e\u4fdd\u5c06Python\u7684Scripts\u6587\u4ef6\u5939\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u5426\u5219\u53ef\u80fd\u65e0\u6cd5\u8fd0\u884cPip\u3002<\/p>\n

**\u4f7f\u7528\u6b65\u9aa4**<\/p>\n

1. \u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n

“`python<\/p>\n

# hello.py<\/p>\n

def main():<\/p>\n

print(“Hello, World!”)<\/p>\n

if __name__ == “__main__”:<\/p>\n

main()<\/p>\n

“`<\/p>\n

2. \u6253\u5f00\u547d<\/p>\n

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

\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u7136\u540e\u5bfc\u822a\u81f3\u5305\u542bPython\u811a\u672c\u7684\u6587\u4ef6\u5939\u3002\u4f8b\u5982\uff0c\u5982\u679c\u811a\u672c\u4f4d\u4e8eD:\\MyScripts\u4e2d\uff0c\u5219\u5e94\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`sh<\/p>\n

cd D:\\MyScripts<\/p>\n

“`<\/p>\n

3. \u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`sh<\/p>\n

pyinstaller –onefile hello.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c`–onefile`\u9009\u9879\u662f\u544a\u8bc9PyInstaller\u5c06\u7a0b\u5e8f\u7684\u6240\u6709\u4f9d\u8d56\u9879\u548c\u811a\u672c\u6587\u4ef6\u6253\u5305\u5230\u4e00\u4e2a\u5355\u72ec\u7684.exe\u6587\u4ef6\u4e2d\u3002<\/p>\n

4. PyInstaller\u5c06\u5206\u6790\u811a\u672c\u5e76\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5c06\u5728\u5f53\u524d\u6587\u4ef6\u5939\u7684\u201cdist\u201d\u5b50\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

**\u6ce8\u610f\u4e8b\u9879**<\/p>\n

– \u6267\u884c\u6b64\u8fc7\u7a0b\u65f6\uff0cPyInstaller\u53ef\u80fd\u4f1a\u4ea7\u751f\u5f88\u591a\u4e2d\u95f4\u6587\u4ef6\uff0c\u5982\u7eaf\u6587\u672c\u53ef\u4ee5\u6253\u5305\u6210exe\u683c\u5f0f\u7684\u8f6f\u4ef6\u662f<\/a>\u65e5\u5fd7\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u66f4\u591a\u547d\u4ee4\u884c\u53c2\u6570\u6765\u89e3\u51b3\u3002\u4f8b\u5982\u53ef\u4ee5\u6dfb\u52a0\u53c2\u6570`–clean`\u548c`–noconfirm`\u6765\u51cf\u5c11\u6587\u4ef6\u751f\u6210\u548c\u81ea\u52a8\u6e05\u9664\u8fc7\u7a0b\u6587\u4ef6\uff1a<\/p>\n

“`sh<\/p>\n

pyinstaller –onefile –clean –noconfirm hello.py<\/p>\n

“`<\/p>\n

– \u5373\u4f7f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff0cPython\u811a\u672c\u4ecd\u7136\u9700\u8981\u67d0\u79cd\u5f62\u5f0f\u7684Python\u8fd0\u884c\u65f6\u6765\u6267\u884c\u3002PyInstaller\u4f1a\u81ea\u52a8\u5c06\u76f8\u5e94\u7248\u672c\u7684Python\u8fd0\u884c\u65f6\u5d4c\u5165\u751f\u6210\u7684.exe\u6587\u4ef6\u4e2d\u3002\u8fd9\u610f\u5473\u7740\u751f\u6210\u7684\u6587\u4ef6\u53ef\u80fd\u6bd4\u9884\u671f\u66f4\u5927\uff0c\u4f46\u59cb\u7ec8\u4f1a\u4e0e\u6e90\u4ee3\u7801\u517c\u5bb9\u3002<\/p>\n

– \u5982\u679c\u6e90\u4ee3\u7801\u4f9d\u8d56\u5916\u90e8\u5e93\uff0c\u8bf7\u786e\u4fdd\u5728\u8fd0\u884cPyInstaller\u4e4b\u524d\u5df2\u5b89\u88c5\u8fd9\u4e9b\u5e93\u3002\u5426\u5219\uff0c\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u80fd\u51fa\u73b0\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/p>\n

– \u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u80fd\u88ab\u6807\u8bb0\u4e3a\u6076\u610f\u8f6f\u4ef6\u3002\u8fd9\u662f\u56e0\u4e3a\u4e00\u4e9b\u6076\u610f\u8f6f\u4ef6\u4e5f\u5c06\u81ea\u5df1\u6253\u5305\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u56e0\u6b64\uff0c\u5728\u5c06\u751f\u6210\u7684\u6587\u4ef6\u53d1\u9001\u7ed9\u5176\u4ed6\u7528\u6237\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u68c0\u67e5\u5176\u5b89\u5168\u6027\u3002<\/p>\n

\u73b0\u5728\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528PyInstaller\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8fc7\u7a0b\u548c\u6ce8\u610f\u4e8b\u9879\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\u987a\u5229\u751f\u6210.exe\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728Python\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5c06Python\u811a\u672c (.py) \u8f6c\u6362\u6210\u53ef\u6267\u884c\u6587\u4ef6 (.exe) \u4ee5\u8ba9\u5176\u4ed6\u7528\u6237\u66f4\u65b9\u4fbf\u5730\u8fd0\u884c\u7a0b\u5e8f\uff0c\u800c\u4ed6\u4eec\u53ef\u80fd\u6ca1\u6709\u5b89\u88c5Python\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u4e3a\u4f60\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyI<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[11582,24,11583,12,2306],"topic":[],"class_list":{"0":"post-6416","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-zhuomianruanjian","7":"tag-exe","8":"tag-24","10":"tag-12","11":"tag-2306"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/6416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=6416"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/6416\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=6416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=6416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=6416"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=6416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}