{"id":955567,"date":"2024-12-27T02:18:28","date_gmt":"2024-12-26T18:18:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/955567.html"},"modified":"2024-12-27T02:18:30","modified_gmt":"2024-12-26T18:18:30","slug":"python-qt%e5%a6%82%e4%bd%95%e5%b0%81%e8%a3%85exe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/955567.html","title":{"rendered":"python qt\u5982\u4f55\u5c01\u88c5exe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095442\/156625e6-b0e0-4ef9-8d88-66631543fdd9.webp\" alt=\"python qt\u5982\u4f55\u5c01\u88c5exe\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528PyInstaller\u3001\u521b\u5efa.spec\u6587\u4ef6\u3001\u5904\u7406\u8d44\u6e90\u6587\u4ef6\u3001\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3001\u4f18\u5316\u6587\u4ef6\u5927\u5c0f<\/strong>\u662f\u5c06Python Qt\u5e94\u7528\u7a0b\u5e8f\u5c01\u88c5\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5173\u952e\u6b65\u9aa4\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5e2e\u52a9\u60a8\u6210\u529f\u5730\u5c06Python Qt\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u72ec\u7acb\u7684.exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001PYINSTALLER\u5b89\u88c5\u4e0e\u57fa\u7840\u4f7f\u7528<\/p>\n<\/p>\n<p><p>PyInstaller\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728\u4f7f\u7528PyInstaller\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u5b83\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5PyInstaller<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u5b89\u88c5PyInstaller\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>pyinstaller<\/code>\u547d\u4ee4\u6765\u68c0\u67e5\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528PyInstaller\u6253\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528PyInstaller\u6253\u5305Qt\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\u3002\u5047\u8bbe\u60a8\u7684\u4e3b\u7a0b\u5e8f\u6587\u4ef6\u540d\u4e3a<code>m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/code>\uff0c\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<code>--onefile<\/code>\u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u751f\u6210.spec\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u521d\u6b21\u8fd0\u884cPyInstaller\u65f6\uff0c\u5b83\u4f1a\u751f\u6210\u4e00\u4e2a.spec\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5b9a\u4e49\u4e86\u6253\u5305\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e9b\u914d\u7f6e\u53c2\u6570\u3002\u60a8\u53ef\u4ee5\u624b\u52a8\u7f16\u8f91\u8fd9\u4e2a\u6587\u4ef6\u6765\u8c03\u6574\u6253\u5305\u884c\u4e3a\uff0c\u4f8b\u5982\u6dfb\u52a0\u989d\u5916\u7684\u6587\u4ef6\u3001\u4fee\u6539\u8def\u5f84\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --name MyApp main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>MyApp.spec<\/code>\u7684\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u505a\u8fdb\u4e00\u6b65\u7684\u914d\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u521b\u5efa.SPEC\u6587\u4ef6\u5e76\u914d\u7f6e<\/p>\n<\/p>\n<p><p>.spec\u6587\u4ef6\u662fPyInstaller\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u5b9a\u4e49\u6253\u5305\u7684\u5404\u79cd\u7ec6\u8282\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4fee\u6539.spec\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>.spec\u6587\u4ef6\u662f\u4e00\u4e2aPython\u811a\u672c\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee3\u7801\u6765\u4fee\u6539\u6253\u5305\u8fc7\u7a0b\u3002\u5e38\u89c1\u7684\u4fee\u6539\u5305\u62ec\u6dfb\u52a0\u989d\u5916\u7684\u6570\u636e\u6587\u4ef6\u3001\u52a8\u6001\u94fe\u63a5\u5e93\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = Analysis([&#39;main.py&#39;],<\/p>\n<p>             pathex=[&#39;\/path\/to\/your\/project&#39;],<\/p>\n<p>             binaries=[],<\/p>\n<p>             datas=[(&#39;path\/to\/datafile&#39;, &#39;destination\/folder&#39;)],<\/p>\n<p>             ...<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728<code>datas<\/code>\u5b57\u6bb5\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6307\u5b9a\u9700\u8981\u5305\u542b\u7684\u989d\u5916\u6570\u636e\u6587\u4ef6\u53ca\u5176\u76ee\u6807\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u8d44\u6e90\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728Qt\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u60a8\u53ef\u80fd\u4f1a\u7528\u5230\u4e00\u4e9b\u8d44\u6e90\u6587\u4ef6\uff0c\u5982\u56fe\u6807\u3001\u56fe\u7247\u7b49\u3002\u60a8\u9700\u8981\u786e\u4fdd\u8fd9\u4e9b\u6587\u4ef6\u5728\u6253\u5305\u65f6\u88ab\u6b63\u786e\u5305\u542b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a.datas += [(&#39;icon.ico&#39;, &#39;.&#39;)]<\/p>\n<p>exe = EXE(a.scripts,<\/p>\n<p>          ...<\/p>\n<p>          icon=&#39;icon.ico&#39;,<\/p>\n<p>          ...<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c06<code>icon.ico<\/code>\u6587\u4ef6\u6dfb\u52a0\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u5e76\u8bbe\u7f6e\u4e3a\u5e94\u7528\u7a0b\u5e8f\u7684\u56fe\u6807\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5904\u7406\u8d44\u6e90\u6587\u4ef6\u4e0e\u8def\u5f84<\/p>\n<\/p>\n<p><p>\u5728\u6253\u5305Qt\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6b63\u786e\u5904\u7406\u8d44\u6e90\u6587\u4ef6\u548c\u8def\u5f84\u662f\u5173\u952e\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u90a3\u4e9b\u5728\u5f00\u53d1\u73af\u5883\u4e2d\u901a\u8fc7\u76f8\u5bf9\u8def\u5f84\u8bbf\u95ee\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u6765\u8bbf\u95ee\u8d44\u6e90\u6587\u4ef6\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u505a\u6cd5\u3002\u7136\u800c\uff0c\u5728\u6253\u5305\u65f6\uff0c\u8fd9\u4e9b\u8def\u5f84\u53ef\u80fd\u9700\u8981\u8c03\u6574\u3002\u60a8\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528<code>os.path<\/code>\u6a21\u5757\u6765\u52a8\u6001\u83b7\u53d6\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>BASE_DIR = os.path.dirname(os.path.abspath(__file__))<\/p>\n<p>resource_path = os.path.join(BASE_DIR, &#39;resources&#39;, &#39;image.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u5728\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u4ecd\u7136\u80fd\u591f\u6b63\u786e\u8bbf\u95ee\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5c06\u8d44\u6e90\u6587\u4ef6\u6253\u5305\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d<\/strong><\/p>\n<\/p>\n<p><p>\u5728.spec\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>datas<\/code>\u53c2\u6570\u6765\u786e\u4fdd\u8d44\u6e90\u6587\u4ef6\u88ab\u5305\u542b\u5728\u6253\u5305\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">datas=[(&#39;resources\/image.png&#39;, &#39;resources&#39;)],<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5c06\u80fd\u591f\u8bbf\u95ee\u8fd9\u4e9b\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6d4b\u8bd5\u4e0e\u8c03\u8bd5<\/p>\n<\/p>\n<p><p>\u5728\u6253\u5305\u5b8c\u6210\u540e\uff0c\u60a8\u9700\u8981\u5bf9\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u5176\u80fd\u591f\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8fd0\u884c\u6d4b\u8bd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6253\u5305\u540e\u7684<code>dist<\/code>\u76ee\u5f55\u4e2d\uff0c\u627e\u5230\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u8fd0\u884c\u5b83\u3002\u5982\u679c\u7a0b\u5e8f\u6b63\u5e38\u542f\u52a8\u5e76\u4e14\u6240\u6709\u529f\u80fd\u90fd\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\uff0c\u90a3\u4e48\u60a8\u7684\u6253\u5305\u8fc7\u7a0b\u5c31\u662f\u6210\u529f\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u7a0b\u5e8f\u65e0\u6cd5\u542f\u52a8\u6216\u51fa\u73b0\u9519\u8bef\u4fe1\u606f\uff0c\u60a8\u9700\u8981\u4ed4\u7ec6\u68c0\u67e5\u9519\u8bef\u65e5\u5fd7\u3002\u5e38\u89c1\u7684\u95ee\u9898\u5305\u62ec\u7f3a\u5c11\u52a8\u6001\u94fe\u63a5\u5e93\u3001\u8d44\u6e90\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u7b49\u3002\u6839\u636e\u9519\u8bef\u4fe1\u606f\uff0c\u9010\u6b65\u6392\u67e5\u5e76\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u52a8\u6001\u94fe\u63a5\u5e93\u7f3a\u5931<\/strong>\uff1a\u68c0\u67e5.spec\u6587\u4ef6\u4e2d\u7684<code>binaries<\/code>\u53c2\u6570\uff0c\u786e\u4fdd\u6240\u6709\u9700\u8981\u7684\u5e93\u90fd\u88ab\u6b63\u786e\u5305\u542b\u3002<\/li>\n<li><strong>\u8d44\u6e90\u6587\u4ef6\u8def\u5f84\u9519\u8bef<\/strong>\uff1a\u68c0\u67e5\u60a8\u7684\u7a0b\u5e8f\u4ee3\u7801\u548c.spec\u6587\u4ef6\uff0c\u786e\u4fdd\u6240\u6709\u8def\u5f84\u90fd\u6b63\u786e\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4f18\u5316\u6587\u4ef6\u5927\u5c0f<\/p>\n<\/p>\n<p><p>\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u80fd\u4f1a\u6bd4\u8f83\u5927\uff0c\u60a8\u53ef\u4ee5\u91c7\u53d6\u4e00\u4e9b\u63aa\u65bd\u6765\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6392\u9664\u4e0d\u5fc5\u8981\u7684\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5728.spec\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>excludes<\/code>\u53c2\u6570\u6765\u6392\u9664\u4e0d\u5fc5\u8981\u7684\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">excludes=[&#39;tkinter&#39;, &#39;unittest&#39;],<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u51cf\u5c11\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528UPX\u538b\u7f29<\/strong><\/p>\n<\/p>\n<p><p>UPX\u662f\u4e00\u79cd\u53ef\u6267\u884c\u6587\u4ef6\u538b\u7f29\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u7528\u5b83\u6765\u538b\u7f29\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u4e0b\u8f7d\u5e76\u5b89\u88c5UPX\uff0c\u7136\u540e\u5728\u6253\u5305\u65f6\u4f7f\u7528<code>--upx-dir<\/code>\u9009\u9879\u6307\u5b9aUPX\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --upx-dir=\/path\/to\/upx main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u8457\u51cf\u5c0f\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u5730\u5c06Python Qt\u5e94\u7528\u7a0b\u5e8f\u5c01\u88c5\u4e3a\u72ec\u7acb\u7684.exe\u6587\u4ef6\u3002\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u9700\u8981\u7279\u522b\u6ce8\u610f\u8d44\u6e90\u6587\u4ef6\u7684\u5904\u7406\u548c\u8def\u5f84\u7684\u6b63\u786e\u914d\u7f6e\u3002\u6b64\u5916\uff0c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u662f\u786e\u4fdd\u6253\u5305\u6210\u529f\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u52a1\u5fc5\u4ed4\u7ec6\u68c0\u67e5\u5e76\u89e3\u51b3\u6240\u6709\u53ef\u80fd\u7684\u95ee\u9898\u3002\u6700\u540e\uff0c\u901a\u8fc7\u4f18\u5316\u6587\u4ef6\u5927\u5c0f\uff0c\u60a8\u53ef\u4ee5\u751f\u6210\u66f4\u4e3a\u7cbe\u7b80\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u52a9\u60a8\u987a\u5229\u5b8c\u6210Python Qt\u5e94\u7528\u7a0b\u5e8f\u7684\u5c01\u88c5\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python Qt\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u5c06Python Qt\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u4f7f\u7528PyInstaller\u6216cx_Freeze\u7b49\u5de5\u5177\u3002PyInstaller\u662f\u6700\u5e38\u7528\u7684\u9009\u62e9\uff0c\u53ea\u9700\u5b89\u88c5PyInstaller\uff0c\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c<code>pyinstaller your_script.py<\/code>\uff0c\u5c31\u80fd\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u786e\u4fdd\u5728\u6253\u5305\u524d\u5df2\u5c06\u6240\u6709\u4f9d\u8d56\u5e93\u5b89\u88c5\u9f50\u5168\uff0c\u5e76\u6839\u636e\u9700\u6c42\u914d\u7f6e.spec\u6587\u4ef6\u4ee5\u8c03\u6574\u6253\u5305\u9009\u9879\u3002<\/p>\n<p><strong>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\u5982\u4f55\u5904\u7406\u5916\u90e8\u8d44\u6e90\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python Qt\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u4f7f\u7528\u4e86\u5916\u90e8\u8d44\u6e90\u6587\u4ef6\uff0c\u5982\u56fe\u50cf\u6216\u914d\u7f6e\u6587\u4ef6\uff0c\u9700\u8981\u5728\u6253\u5305\u65f6\u786e\u4fdd\u8fd9\u4e9b\u6587\u4ef6\u4e5f\u5305\u542b\u5728\u5185\u3002\u53ef\u4ee5\u5728PyInstaller\u7684.spec\u6587\u4ef6\u4e2d\u6307\u5b9a\u6570\u636e\u6587\u4ef6\uff0c\u5c06\u5176\u6dfb\u52a0\u5230<code>datas<\/code>\u5217\u8868\u4e2d\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>datas=[(&#39;path\/to\/resource&#39;, &#39;destination\/path&#39;)]<\/code>\u6765\u786e\u4fdd\u8d44\u6e90\u6587\u4ef6\u88ab\u6b63\u786e\u6253\u5305\u3002<\/p>\n<p><strong>\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u5728\u5176\u4ed6\u8ba1\u7b97\u673a\u4e0a\u80fd\u5426\u8fd0\u884c\uff1f<\/strong><br \/>\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u53ef\u4ee5\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002\u786e\u4fdd\u5728\u6253\u5305\u65f6\u9009\u62e9\u4e86\u9002\u5408\u76ee\u6807\u5e73\u53f0\u7684\u8bbe\u7f6e\uff0c\u5e76\u5c06\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u5305\u62ec\u5728\u5185\u3002\u4e0d\u8fc7\uff0c\u67d0\u4e9b\u7cfb\u7edf\u7279\u5b9a\u7684\u5e93\u53ef\u80fd\u9700\u8981\u5728\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u9884\u5148\u5b89\u88c5\uff0c\u5efa\u8bae\u5728\u4e0d\u540c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u4ee5\u786e\u4fdd\u517c\u5bb9\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528PyInstaller\u3001\u521b\u5efa.spec\u6587\u4ef6\u3001\u5904\u7406\u8d44\u6e90\u6587\u4ef6\u3001\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3001\u4f18\u5316\u6587\u4ef6\u5927\u5c0f\u662f\u5c06Python Qt\u5e94 [&hellip;]","protected":false},"author":3,"featured_media":955569,"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\/955567"}],"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=955567"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/955567\/revisions"}],"predecessor-version":[{"id":955570,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/955567\/revisions\/955570"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/955569"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=955567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=955567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=955567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}