{"id":389,"date":"2025-12-02T15:20:42","date_gmt":"2025-12-02T07:20:42","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=389"},"modified":"2025-12-02T15:20:42","modified_gmt":"2025-12-02T07:20:42","slug":"pyinstaller%e7%bc%96%e8%af%91exe%e4%b8%8e%e5%8f%8d%e7%bc%96%e8%af%91_exe%e5%8f%8d%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/02\/pyinstaller%e7%bc%96%e8%af%91exe%e4%b8%8e%e5%8f%8d%e7%bc%96%e8%af%91_exe%e5%8f%8d%e7%bc%96%e8%af%91\/","title":{"rendered":"PyInstaller:\u7f16\u8bd1exe\u4e0e\u53cd\u7f16\u8bd1_exe\u53cd\u7f16\u8bd1"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>PyInstaller \u6253\u5305 EXE \u4e0e\u5e38\u89c1\u7684 EXE \u53cd\u7f16\u8bd1\u65b9\u6cd5\uff08\u542b\u6ce8\u610f\u4e8b\u9879\uff09<\/strong> \u7684\u6e05\u6670\u603b\u7ed3\uff0c\u9002\u5408\u5165\u95e8\u4e0e\u6392\u67e5\u95ee\u9898\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udc0d PyInstaller\uff1a\u7f16\u8bd1 EXE \u4e0e\u53cd\u7f16\u8bd1\u6307\u5357<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001PyInstaller \u6253\u5305 EXE\uff08\u7f16\u8bd1\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 1. \u5b89\u88c5 PyInstaller<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install pyinstaller\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2705 2. \u6700\u7b80\u5355\u6253\u5305<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller your_script.py\n\n<\/pre><\/div>\n\n\n<p>\u751f\u6210\u76ee\u5f55\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>build\/<\/code><\/li>\n\n\n\n<li><code>dist\/your_script\/<\/code><\/li>\n\n\n\n<li><code>your_script.spec<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u8fd0\u884c EXE\uff1a<br><code>dist\/your_script\/your_script.exe<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd12 3. \u5e38\u7528\u6253\u5305\u53c2\u6570\uff08\u5f3a\u70c8\u63a8\u8350\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5355\u6587\u4ef6\u6253\u5305\uff08\u2013onefile\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F your_script.py\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u53bb\u9664\u547d\u4ee4\u884c\u7a97\u53e3\uff08GUI\u7a0b\u5e8f\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F -w your_script.py\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u6dfb\u52a0\u56fe\u6807<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F -i myicon.ico your_script.py\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5305\u542b\u989d\u5916\u6587\u4ef6\uff08\u5982\u6a21\u578b\u3001\u914d\u7f6e\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F your_script.py --add-data &quot;config.yaml;.&quot;\n\n<\/pre><\/div>\n\n\n<p>\u6ce8\u610f\uff1aWindows \u4f7f\u7528 <code>;<\/code>\uff0cLinux \/ macOS \u4f7f\u7528 <code>:<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 4. \u6253\u5305\u540e\u5e38\u89c1\u95ee\u9898<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2757 \u8fd0\u884c\u65f6\u62a5\u9519 \u201cno module named xxx\u201d<\/h3>\n\n\n\n<p>\u901a\u5e38\u539f\u56e0\uff1a\u4f9d\u8d56\u672a\u88ab\u81ea\u52a8\u68c0\u6d4b<br>\u89e3\u51b3\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F your_script.py --hidden-import package_name\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2757 \u7a0b\u5e8f\u5728\u5176\u4ed6\u7535\u8111\u6253\u4e0d\u5f00\uff08\u7f3a\u7ec4\u4ef6\uff09<\/h3>\n\n\n\n<p>\u6700\u5e38\u89c1\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fd0\u884c\u73af\u5883\u7f3a\u5fae\u8f6f VC++ \u8fd0\u884c\u5e93<\/li>\n\n\n\n<li>\u8def\u5f84\u4e2d\u6709\u4e2d\u6587\u5bfc\u81f4\u8def\u5f84\u89e3\u6790\u9519\u8bef<\/li>\n\n\n\n<li>\u6743\u9650\u4e0d\u8db3\uff08UAC \u62e6\u622a\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddd0 \u4e8c\u3001EXE \u53cd\u7f16\u8bd1\uff08\u5b66\u4e60\u7528\u9014\uff09<\/h1>\n\n\n\n<p><strong>\u26a0\ufe0f \u6ce8\u610f\uff1a\u53cd\u7f16\u8bd1\u5de5\u5177\u4ec5\u7528\u4e8e\u81ea\u5df1\u8f6f\u4ef6\u5206\u6790\u4e0e\u5b66\u4e60\uff0c\u4e0d\u5f97\u7528\u4e8e\u9006\u5411\u7834\u89e3\u4ed6\u4eba\u8f6f\u4ef6\uff01<\/strong><\/p>\n\n\n\n<p>PyInstaller \u6253\u5305\u7684 EXE <strong>\u5e76\u4e0d\u662f\u5b8c\u5168\u4e0d\u53ef\u9006<\/strong>\uff0c\u73b0\u6709\u5de5\u5177\u53ef\u4ee5 80% \u6062\u590d\u4ee3\u7801\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd13 1. pyinstxtractor\uff08\u4ece EXE \u63d0\u53d6 pyc\uff09<\/h2>\n\n\n\n<p>GitHub\uff1a<code>pyinstxtractor.py<\/code><\/p>\n\n\n\n<p>\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npython pyinstxtractor.py your_script.exe\n\n<\/pre><\/div>\n\n\n<p>\u8f93\u51fa\u5185\u5bb9\u91cc\u4f1a\u5305\u542b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.pyc<\/code> \u6587\u4ef6<\/li>\n\n\n\n<li>\u7a0b\u5e8f\u8d44\u6e90<\/li>\n\n\n\n<li>\u914d\u7f6e\u6587\u4ef6\u7b49<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd13 2. \u53cd\u7f16\u8bd1 pyc \u2192 py<\/h2>\n\n\n\n<p>\u7528 <code>uncompyle6<\/code> \u6216 <code>decompyle3<\/code>\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install uncompyle6\nuncompyle6 extracted_file.pyc\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd10 3. \u5982\u4f55\u589e\u52a0\u53cd\u7f16\u8bd1\u96be\u5ea6\uff1f\uff08\u4e0d\u662f\u7edd\u5bf9\u5b89\u5168\uff09<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 <strong>UPX \u538b\u7f29<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npyinstaller -F your.py --upx-dir UPX_PATH\n\n<\/pre><\/div>\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u4f7f\u7528\u4ee3\u7801\u6df7\u6dc6\u5668\uff08\u5982 pyarmor\uff09<\/li>\n\n\n\n<li>\u4f7f\u7528 Cython \u5c06\u6838\u5fc3\u4ee3\u7801\u751f\u6210 C \u6269\u5c55<\/li>\n\n\n\n<li>\u5173\u952e\u7b97\u6cd5\u653e\u5230\u670d\u52a1\u7aef\uff0c\u4e0d\u653e\u5728\u672c\u5730<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u26a0\ufe0f \u5355\u7eaf PyInstaller \u6253\u5305 \u2260 \u5b89\u5168\u4fdd\u62a4\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udce6 \u4e09\u3001\u603b\u7ed3<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u64cd\u4f5c<\/th><th>\u5de5\u5177\/\u547d\u4ee4<\/th><\/tr><\/thead><tbody><tr><td>PyInstaller \u6253\u5305<\/td><td><code>pyinstaller -F your.py<\/code><\/td><\/tr><tr><td>\u5355\u6587\u4ef6<\/td><td><code>-F<\/code><\/td><\/tr><tr><td>GUI<\/td><td><code>-w<\/code><\/td><\/tr><tr><td>\u56fe\u6807<\/td><td><code>-i xxx.ico<\/code><\/td><\/tr><tr><td>\u9690\u85cf\u4f9d\u8d56<\/td><td><code>--hidden-import<\/code><\/td><\/tr><tr><td>\u53cd\u7f16\u8bd1 EXE<\/td><td>pyinstxtractor<\/td><\/tr><tr><td>pyc \u2192 py<\/td><td>uncompyle6 \/ decompyle3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd PyInstaller \u6253\u5305 EXE \u4e0e\u5e38\u89c1\u7684 EXE \u53cd\u7f16\u8bd1\u65b9\u6cd5&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/02\/pyinstaller%e7%bc%96%e8%af%91exe%e4%b8%8e%e5%8f%8d%e7%bc%96%e8%af%91_exe%e5%8f%8d%e7%bc%96%e8%af%91\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-389","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=389"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":390,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/389\/revisions\/390"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}