{"id":998331,"date":"2024-12-27T09:32:02","date_gmt":"2024-12-27T01:32:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/998331.html"},"modified":"2024-12-27T09:32:08","modified_gmt":"2024-12-27T01:32:08","slug":"python%e6%89%93%e5%8c%85%e5%a6%82%e4%bd%95%e5%8f%8d%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/998331.html","title":{"rendered":"python\u6253\u5305\u5982\u4f55\u53cd\u7f16\u8bd1"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073827\/30a6dd9b-a82f-41da-b894-34947f80f54d.webp\" alt=\"python\u6253\u5305\u5982\u4f55\u53cd\u7f16\u8bd1\" \/><\/p>\n<p><p> <strong>Python\u6253\u5305\u7684\u53cd\u7f16\u8bd1\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u53cd\u7f16\u8bd1\u5de5\u5177\u3001\u5206\u6790\u4e8c\u8fdb\u5236\u6587\u4ef6\u3001\u4e86\u89e3\u6253\u5305\u5de5\u5177\u7684\u5de5\u4f5c\u539f\u7406\u6765\u5b9e\u73b0\u3002<\/strong>\u53cd\u7f16\u8bd1Python\u6253\u5305\u7684\u6587\u4ef6\u9700\u8981\u4e00\u5b9a\u7684\u6280\u672f\u57fa\u7840\u548c\u5de5\u5177\u652f\u6301\uff0c\u5e38\u89c1\u7684\u53cd\u7f16\u8bd1\u5de5\u5177\u5305\u62ec<code>uncompyle6<\/code>\u3001<code>pycdc<\/code>\u7b49\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u53ca\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4e86\u89e3Python\u6253\u5305\u539f\u7406<\/p>\n<\/p>\n<p><p>Python\u662f\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u901a\u5e38\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u7f16\u8bd1\u6210\u5b57\u8282\u7801\u3002\u56e0\u6b64\uff0cPython\u7a0b\u5e8f\u53ef\u4ee5\u88ab\u6253\u5305\u6210\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u4ee5\u4fbf\u4e8e\u53d1\u5e03\u548c\u8fd0\u884c\u3002\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u5e38\u7528\u7684\u5de5\u5177\u6709<code>PyInstaller<\/code>\u3001<code>cx_Freeze<\/code>\u7b49\u3002\u8fd9\u4e9b\u5de5\u5177\u4f1a\u5c06Python\u811a\u672c\u53ca\u5176\u4f9d\u8d56\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65b9\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyInstaller\u7684\u5de5\u4f5c\u539f\u7406<\/strong><\/p>\n<\/p>\n<p><p>PyInstaller\u662f\u4e00\u4e2a\u5e38\u7528\u7684Python\u6253\u5305\u5de5\u5177\uff0c\u5b83\u5c06Python\u811a\u672c\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5176\u5de5\u4f5c\u539f\u7406\u662f\u5c06Python\u811a\u672c\u7f16\u8bd1\u6210\u5b57\u8282\u7801\uff0c\u5e76\u5728\u8fd0\u884c\u65f6\u901a\u8fc7\u9644\u5e26\u7684Python\u89e3\u91ca\u5668\u6765\u6267\u884c\u3002PyInstaller\u8fd8\u4f1a\u5c06\u9700\u8981\u7684\u5e93\u548c\u6a21\u5757\u6253\u5305\u8fdb\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u4ee5\u786e\u4fdd\u5728\u76ee\u6807\u673a\u5668\u4e0a\u53ef\u4ee5\u6b63\u786e\u8fd0\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cx_Freeze\u7684\u5de5\u4f5c\u539f\u7406<\/strong><\/p>\n<\/p>\n<p><p>cx_Freeze\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u6253\u5305\u5de5\u5177\uff0c\u5176\u539f\u7406\u4e0ePyInstaller\u7c7b\u4f3c\u3002cx_Freeze\u5c06Python\u811a\u672c\u548c\u76f8\u5173\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u5305\u542bPython\u89e3\u91ca\u5668\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002cx_Freeze\u652f\u6301\u591a\u5e73\u53f0\uff0c\u53ef\u4ee5\u751f\u6210Windows\u3001Linux\u548cMacOS\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u53cd\u7f16\u8bd1\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u53cd\u7f16\u8bd1\u5de5\u5177\u53ef\u4ee5\u5c06\u6253\u5305\u540e\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u8fd8\u539f\u4e3a\u539f\u59cb\u7684Python\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684Python\u53cd\u7f16\u8bd1\u5de5\u5177\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>uncompyle6<\/strong><\/p>\n<\/p>\n<p><p><code>uncompyle6<\/code>\u662f\u4e00\u4e2a\u652f\u6301Python 2.7\u52303.9\u5b57\u8282\u7801\u7684\u53cd\u7f16\u8bd1\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u5c06<code>.pyc<\/code>\u6216<code>.pyo<\/code>\u6587\u4ef6\u53cd\u7f16\u8bd1\u6210\u53ef\u8bfb\u7684Python\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install uncompyle6<\/p>\n<p>uncompyle6 -o &lt;output_directory&gt; &lt;compiled_file&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>&lt;output_directory&gt;<\/code>\u662f\u53cd\u7f16\u8bd1\u540e\u7684\u6587\u4ef6\u5b58\u653e\u8def\u5f84\uff0c<code>&lt;compiled_file&gt;<\/code>\u662f\u5f85\u53cd\u7f16\u8bd1\u7684\u5b57\u8282\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>pycdc<\/strong><\/p>\n<\/p>\n<p><p><code>pycdc<\/code>\uff08Python Bytecode Disassembler and Decompiler\uff09\u662f\u4e00\u6b3e\u53cd\u7f16\u8bd1\u5de5\u5177\uff0c\u652f\u6301Python 3.5\u53ca\u4ee5\u4e0a\u7248\u672c\u7684\u5b57\u8282\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pycdc &lt;compiled_file&gt; &gt; &lt;output_file&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>&lt;compiled_file&gt;<\/code>\u662f\u5f85\u53cd\u7f16\u8bd1\u7684\u5b57\u8282\u7801\u6587\u4ef6\uff0c<code>&lt;output_file&gt;<\/code>\u662f\u8f93\u51fa\u7684Python\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5206\u6790\u6253\u5305\u6587\u4ef6<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u63d0\u53d6\u5b57\u8282\u7801\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u53cd\u7f16\u8bd1\u5de5\u5177\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u4ece\u6253\u5305\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u63d0\u53d6\u51fa\u5b57\u8282\u7801\u6587\u4ef6\u3002\u8fd9\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u89e3\u538b\u7f29\u5de5\u5177\uff08\u5982<code>7-Zip<\/code>\u3001<code>WinRAR<\/code>\uff09\u6765\u5b8c\u6210\u3002\u6253\u5305\u5de5\u5177\u901a\u5e38\u4f1a\u5c06\u5b57\u8282\u7801\u6587\u4ef6\u5b58\u653e\u5728\u7279\u5b9a\u7684\u76ee\u5f55\u4e2d\uff0c\u5982<code>PyInstaller<\/code>\u6253\u5305\u7684\u6587\u4ef6\u4e2d\u5e38\u89c1\u7684<code>PYZ<\/code>\u538b\u7f29\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bc6\u522b\u5b57\u8282\u7801\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u63d0\u53d6\u5b57\u8282\u7801\u6587\u4ef6\u540e\uff0c\u9700\u8981\u8bc6\u522b\u54ea\u4e9b\u662fPython\u5b57\u8282\u7801\u6587\u4ef6\u3002\u901a\u5e38\uff0cPython\u5b57\u8282\u7801\u6587\u4ef6\u4ee5<code>.pyc<\/code>\u6216<code>.pyo<\/code>\u4e3a\u540e\u7f00\u3002\u53ef\u4ee5\u901a\u8fc7\u6587\u4ef6\u5934\u4fe1\u606f\u6765\u786e\u8ba4\u6587\u4ef6\u7c7b\u578b\uff0cPython\u5b57\u8282\u7801\u6587\u4ef6\u901a\u5e38\u4ee5<code>0x03<\/code>\u3001<code>0xF3<\/code>\u3001<code>0x0D<\/code>\u3001<code>0x0A<\/code>\u4e3a\u5f00\u5934\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u6cd5\u5f8b\u5408\u89c4<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5408\u6cd5\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u53cd\u7f16\u8bd1\u4ed6\u4eba\u7684\u8f6f\u4ef6\u53ef\u80fd\u6d89\u53ca\u6cd5\u5f8b\u95ee\u9898\u3002\u5728\u8fdb\u884c\u53cd\u7f16\u8bd1\u4e4b\u524d\uff0c\u52a1\u5fc5\u786e\u4fdd\u62e5\u6709\u5408\u6cd5\u7684\u6743\u9650\u548c\u6388\u6743\u3002\u53cd\u7f16\u8bd1\u901a\u5e38\u9002\u7528\u4e8e\u5b66\u4e60\u548c\u7814\u7a76\u76ee\u7684\uff0c\u4e0d\u5e94\u7528\u4e8e\u6076\u610f\u6d3b\u52a8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u590d\u6742\u6027<\/strong><\/p>\n<\/p>\n<p><p>Python\u6253\u5305\u6587\u4ef6\u7684\u53cd\u7f16\u8bd1\u53ef\u80fd\u4f1a\u9047\u5230\u56f0\u96be\uff0c\u5c24\u5176\u662f\u5f53\u6587\u4ef6\u7ecf\u8fc7\u6df7\u6dc6\u6216\u52a0\u5bc6\u5904\u7406\u65f6\u3002\u56e0\u6b64\uff0c\u638c\u63e1\u76f8\u5173\u5de5\u5177\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u5b57\u8282\u7801\u7684\u5de5\u4f5c\u539f\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b57\u8282\u7801\u4f18\u5316<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u4e9b\u6253\u5305\u5de5\u5177\u53ef\u80fd\u4f1a\u5bf9\u5b57\u8282\u7801\u8fdb\u884c\u4f18\u5316\uff0c\u8fd9\u4f1a\u589e\u52a0\u53cd\u7f16\u8bd1\u7684\u96be\u5ea6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u501f\u52a9\u66f4\u591a\u7684\u5de5\u5177\u548c\u6280\u672f\u624b\u6bb5\u8fdb\u884c\u6df1\u5165\u5206\u6790\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\u548c\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u53cd\u7f16\u8bd1Python\u6253\u5305\u7684\u6587\u4ef6\u3002\u4e0d\u8fc7\uff0c\u53cd\u7f16\u8bd1\u662f\u4e00\u9879\u590d\u6742\u7684\u6280\u672f\u5de5\u4f5c\uff0c\u9700\u8981\u5177\u5907\u4e00\u5b9a\u7684\u7f16\u7a0b\u548c\u8ba1\u7b97\u673a\u77e5\u8bc6\u3002\u5e0c\u671b\u672c\u6587\u7684\u4ecb\u7ecd\u80fd\u591f\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e9b\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u6253\u5305\u7684Python\u7a0b\u5e8f\u662f\u5426\u53ef\u4ee5\u88ab\u53cd\u7f16\u8bd1\uff1f<\/strong><br \/>\u6253\u5305\u7684Python\u7a0b\u5e8f\u901a\u5e38\u4f1a\u88ab\u8f6c\u6362\u4e3a\u5b57\u8282\u7801\uff0c\u8fd9\u79cd\u5f62\u5f0f\u867d\u7136\u589e\u52a0\u4e86\u53cd\u7f16\u8bd1\u7684\u96be\u5ea6\uff0c\u4f46\u5e76\u4e0d\u80fd\u5b8c\u5168\u9632\u6b62\u3002\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5de5\u5177\uff08\u5982pyinstxtractor\uff09\u6765\u6d4b\u8bd5\u6253\u5305\u540e\u7684\u7a0b\u5e8f\u662f\u5426\u5bb9\u6613\u53cd\u7f16\u8bd1\u3002\u6700\u597d\u7684\u505a\u6cd5\u662f\u4fdd\u6301\u4ee3\u7801\u7684\u7b80\u6d01\u6027\uff0c\u907f\u514d\u5728\u4ee3\u7801\u4e2d\u5305\u542b\u654f\u611f\u4fe1\u606f\u3002<\/p>\n<p><strong>\u53cd\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\u8d28\u91cf\u5982\u4f55\uff1f<\/strong><br \/>\u53cd\u7f16\u8bd1\u5de5\u5177\u751f\u6210\u7684\u4ee3\u7801\u8d28\u91cf\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u901a\u5e38\u4f1a\u7f3a\u5c11\u539f\u59cb\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u548c\u683c\u5f0f\uff0c\u53d8\u91cf\u540d\u548c\u51fd\u6570\u540d\u4e5f\u53ef\u80fd\u88ab\u66ff\u6362\u4e3a\u65e0\u610f\u4e49\u7684\u540d\u79f0\u3002\u8fd9\u4f7f\u5f97\u53cd\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\u53ef\u80fd\u96be\u4ee5\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u4f46\u4ecd\u7136\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u903b\u8f91\u6765\u6062\u590d\u7a0b\u5e8f\u7684\u529f\u80fd\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u529e\u6cd5\u4fdd\u62a4\u6211\u7684Python\u4ee3\u7801\u4ee5\u9632\u6b62\u53cd\u7f16\u8bd1\uff1f<\/strong><br \/>\u867d\u7136\u6ca1\u6709\u7edd\u5bf9\u7684\u9632\u62a4\u63aa\u65bd\uff0c\u4f46\u53ef\u4ee5\u91c7\u53d6\u4e00\u4e9b\u65b9\u6cd5\u6765\u589e\u5f3a\u4ee3\u7801\u7684\u5b89\u5168\u6027\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Cython\u5c06Python\u4ee3\u7801\u7f16\u8bd1\u4e3aC\u8bed\u8a00\uff0c\u6216\u8005\u4f7f\u7528Pyarmor\u7b49\u5de5\u5177\u8fdb\u884c\u4ee3\u7801\u6df7\u6dc6\uff0c\u589e\u52a0\u53cd\u7f16\u8bd1\u7684\u96be\u5ea6\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u76d1\u6d4b\u548c\u66f4\u65b0\u4ee3\u7801\u7684\u4fdd\u62a4\u63aa\u65bd\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u6253\u5305\u7684\u53cd\u7f16\u8bd1\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u53cd\u7f16\u8bd1\u5de5\u5177\u3001\u5206\u6790\u4e8c\u8fdb\u5236\u6587\u4ef6\u3001\u4e86\u89e3\u6253\u5305\u5de5\u5177\u7684\u5de5\u4f5c\u539f\u7406\u6765\u5b9e\u73b0\u3002\u53cd\u7f16\u8bd1Pytho [&hellip;]","protected":false},"author":3,"featured_media":998339,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/998331"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=998331"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/998331\/revisions"}],"predecessor-version":[{"id":998342,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/998331\/revisions\/998342"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/998339"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=998331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=998331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=998331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}