{"id":1157513,"date":"2025-01-13T18:29:34","date_gmt":"2025-01-13T10:29:34","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1157513.html"},"modified":"2025-01-13T18:29:37","modified_gmt":"2025-01-13T10:29:37","slug":"python%e5%a6%82%e4%bd%95%e5%b0%81%e8%a3%85%e4%b8%baexe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1157513.html","title":{"rendered":"python\u5982\u4f55\u5c01\u88c5\u4e3aexe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25195719\/a238a7d8-cf33-4983-b2f9-aca640b3ab78.webp\" alt=\"python\u5982\u4f55\u5c01\u88c5\u4e3aexe\" \/><\/p>\n<p><p> <strong>Python\u5c01\u88c5\u4e3aEXE\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u4f8b\u5982\uff1a\u4f7f\u7528PyInstaller\u3001cx_Freeze\u3001py2exe\u7b49\u5de5\u5177\u3002<\/strong> \u5176\u4e2d\uff0c\u6700\u5e38\u7528\u548c\u63a8\u8350\u7684\u5de5\u5177\u662f<strong>PyInstaller<\/strong>\uff0c\u56e0\u4e3a\u5b83\u652f\u6301\u591a\u5e73\u53f0\uff0c\u4e14\u914d\u7f6e\u7b80\u5355\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528PyInstaller\u5c06Python\u811a\u672c\u6253\u5305\u6210EXE\u6587\u4ef6\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>PyInstaller\u7684\u5b89\u88c5\u4e0e\u4f7f\u7528<\/h3>\n<\/p>\n<p><h4>\u5b89\u88c5PyInstaller<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u73af\u5883\u548cpip\u5de5\u5177\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5PyInstaller\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u57fa\u672c\u6253\u5305\u547d\u4ee4<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06Python\u811a\u672c\u6253\u5305\u6210EXE\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6267\u884c\u6b64\u547d\u4ee4\u540e\uff0cPyInstaller\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>dist<\/code>\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u6253\u5305\u597d\u7684EXE\u6587\u4ef6\u548c\u76f8\u5173\u7684\u4f9d\u8d56\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u8be6\u7ec6\u914d\u7f6e\u4e0e\u9009\u9879<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u6ee1\u8db3\u4e0d\u540c\u9700\u6c42\uff0cPyInstaller\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u547d\u4ee4\u884c\u9009\u9879\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u9009\u9879\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5355\u6587\u4ef6\u6253\u5305<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u5355\u72ec\u7684EXE\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u65e0\u63a7\u5236\u53f0\u6a21\u5f0f<\/strong>\uff1a\u9002\u7528\u4e8eGUI\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e0d\u4f1a\u5f39\u51fa\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --noconsole your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6307\u5b9a\u56fe\u6807<\/strong>\uff1a\u4e3a\u751f\u6210\u7684EXE\u6587\u4ef6\u6307\u5b9a\u4e00\u4e2a\u56fe\u6807\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --icon=your_icon.ico your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u9644\u52a0\u6570\u636e\u6587\u4ef6<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u811a\u672c\u9700\u8981\u989d\u5916\u7684\u6570\u636e\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--add-data<\/code>\u9009\u9879\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --add-data &quot;data_file.txt;.&quot; your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u914d\u7f6e\u6587\u4ef6\u4e0e\u9ad8\u7ea7\u8bbe\u7f6e<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528PyInstaller\u751f\u6210\u7684<code>spec<\/code>\u6587\u4ef6\u6765\u8fdb\u884c\u9ad8\u7ea7\u914d\u7f6e\u3002<code>spec<\/code>\u6587\u4ef6\u662f\u4e00\u4e2aPython\u811a\u672c\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6253\u5305\u8fc7\u7a0b\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210<code>spec<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --name=your_project_name --specpath=.\/specs your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u7684<code>spec<\/code>\u6587\u4ef6\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u7f16\u8f91\uff0c\u7136\u540e\u518d\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller your_project_name.spec<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6253\u5305\u540e\u7684\u8c03\u8bd5\u4e0e\u4f18\u5316<\/h4>\n<\/p>\n<p><p>\u6253\u5305\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5bf9\u751f\u6210\u7684EXE\u6587\u4ef6\u8fdb\u884c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3002\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u53c2\u8003PyInstaller\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u5b83\u4f1a\u8bb0\u5f55\u6253\u5305\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u6240\u6709\u95ee\u9898\u3002\u5e38\u89c1\u7684\u95ee\u9898\u5305\u62ec\u7f3a\u5c11\u4f9d\u8d56\u5305\u3001\u8def\u5f84\u9519\u8bef\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u51cf\u5c11EXE\u6587\u4ef6\u7684\u4f53\u79ef\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u4f18\u5316\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5265\u79bb\u8c03\u8bd5\u4fe1\u606f<\/strong>\uff1a\u4f7f\u7528<code>--strip<\/code>\u9009\u9879\u5265\u79bb\u8c03\u8bd5\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --strip your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u538b\u7f29\u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528UPX\u5de5\u5177\u5bf9\u751f\u6210\u7684EXE\u6587\u4ef6\u8fdb\u884c\u538b\u7f29\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --upx-dir=path_to_upx your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528cx_Freeze\u6253\u5305<\/h3>\n<\/p>\n<p><h4>\u5b89\u88c5cx_Freeze<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5cx_Freeze\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cx_Freeze<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528cx_Freeze\u6253\u5305<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a<code>setup.py<\/code>\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from cx_Freeze import setup, Executable<\/p>\n<p>setup(<\/p>\n<p>    name = &quot;YourAppName&quot;,<\/p>\n<p>    version = &quot;0.1&quot;,<\/p>\n<p>    description = &quot;Your App Description&quot;,<\/p>\n<p>    executables = [Executable(&quot;your_script.py&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py build<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>cx_Freeze\u5c06\u751f\u6210\u4e00\u4e2a<code>build<\/code>\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u6253\u5305\u597d\u7684EXE\u6587\u4ef6\u548c\u4f9d\u8d56\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528py2exe\u6253\u5305<\/h3>\n<\/p>\n<p><h4>\u5b89\u88c5py2exe<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5py2exe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528py2exe\u6253\u5305<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a<code>setup.py<\/code>\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from distutils.core import setup<\/p>\n<p>import py2exe<\/p>\n<p>setup(<\/p>\n<p>    console=[&#39;your_script.py&#39;],<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>py2exe\u5c06\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u6253\u5305\u597d\u7684EXE\u6587\u4ef6\u548c\u4f9d\u8d56\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h4>\u4f9d\u8d56\u5305\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u6253\u5305\u5de5\u5177\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u8bc6\u522b\u6240\u6709\u7684\u4f9d\u8d56\u5305\u3002\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u6dfb\u52a0\u4f9d\u8d56\u5305\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u5728PyInstaller\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--hidden-import<\/code>\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --hidden-import=some_module your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8def\u5f84\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u6253\u5305\u540e\u7684EXE\u6587\u4ef6\u53ef\u80fd\u4f1a\u9047\u5230\u8def\u5f84\u95ee\u9898\uff0c\u7279\u522b\u662f\u6d89\u53ca\u5230\u76f8\u5bf9\u8def\u5f84\u65f6\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u89e3\u51b3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3002<\/li>\n<li>\u4f7f\u7528<code>os.path<\/code>\u6a21\u5757\u52a8\u6001\u83b7\u53d6\u811a\u672c\u7684\u5f53\u524d\u8def\u5f84\u3002<\/li>\n<\/ul>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u83b7\u53d6\u811a\u672c\u6587\u4ef6\u6240\u5728\u76ee\u5f55<\/strong><\/h2>\n<p>script_dir = os.path.dirname(os.path.abspath(__file__))<\/p>\n<h2><strong>\u62fc\u63a5\u6587\u4ef6\u8def\u5f84<\/strong><\/h2>\n<p>data_file_path = os.path.join(script_dir, &#39;data_file.txt&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u56fe\u6807\u4e0e\u8d44\u6e90\u6587\u4ef6\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5728\u6253\u5305GUI\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u786e\u4fdd\u6240\u6709\u7684\u8d44\u6e90\u6587\u4ef6\uff08\u5982\u56fe\u6807\u3001\u56fe\u7247\u7b49\uff09\u90fd\u5305\u542b\u5728\u6253\u5305\u6587\u4ef6\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u6dfb\u52a0\u8d44\u6e90\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728PyInstaller\u4e2d\u4f7f\u7528<code>--add-data<\/code>\u9009\u9879\u3002<\/li>\n<li>\u5728cx_Freeze\u7684<code>setup<\/code>\u51fd\u6570\u4e2d\u4f7f\u7528<code>include_files<\/code>\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from cx_Freeze import setup, Executable<\/p>\n<p>setup(<\/p>\n<p>    name = &quot;YourAppName&quot;,<\/p>\n<p>    version = &quot;0.1&quot;,<\/p>\n<p>    description = &quot;Your App Description&quot;,<\/p>\n<p>    options = {<\/p>\n<p>        &#39;build_exe&#39;: {<\/p>\n<p>            &#39;include_files&#39;: [&#39;data_file.txt&#39;, &#39;your_icon.ico&#39;]<\/p>\n<p>        }<\/p>\n<p>    },<\/p>\n<p>    executables = [Executable(&quot;your_script.py&quot;, icon=&quot;your_icon.ico&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u5c06Python\u811a\u672c\u5c01\u88c5\u4e3aEXE\u6587\u4ef6\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u6280\u80fd\uff0c\u7279\u522b\u662f\u5f53\u4f60\u9700\u8981\u5c06\u4f60\u7684\u7a0b\u5e8f\u5206\u53d1\u7ed9\u4e0d\u5177\u5907Python\u73af\u5883\u7684\u7528\u6237\u65f6\u3002<strong>PyInstaller\u3001cx_Freeze\u548cpy2exe\u662f\u4e09\u79cd\u5e38\u89c1\u7684\u6253\u5305\u5de5\u5177\uff0c\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u3002<\/strong> \u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u57fa\u672c\u7684\u6253\u5305\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u80fd\u591f\u987a\u5229\u5c06Python\u811a\u672c\u5c01\u88c5\u4e3aEXE\u6587\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u6d41\u884c\u7684\u5de5\u5177\uff0c\u5982PyInstaller\u3001cx_Freeze\u6216py2exe\u3002\u4ee5PyInstaller\u4e3a\u4f8b\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install pyinstaller<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u4f60\u7684Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u8f93\u5165<code>pyinstaller --onefile your_script.py<\/code>\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a\u5355\u72ec\u7684EXE\u6587\u4ef6\uff0c\u4fdd\u5b58\u5728<code>dist<\/code>\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p><strong>\u8f6c\u6362\u4e3aEXE\u540e\uff0c\u5982\u4f55\u786e\u4fdd\u6587\u4ef6\u7684\u517c\u5bb9\u6027\uff1f<\/strong><br \/>\u5728\u5c06Python\u811a\u672c\u6253\u5305\u4e3aEXE\u6587\u4ef6\u65f6\uff0c\u786e\u4fdd\u4f7f\u7528\u7684Python\u7248\u672c\u4e0e\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u7684\u73af\u5883\u517c\u5bb9\u3002\u5bf9\u4e8e\u9700\u8981\u7279\u5b9a\u5e93\u7684\u5e94\u7528\uff0c\u52a1\u5fc5\u5728\u76ee\u6807\u673a\u5668\u4e0a\u5b89\u88c5\u76f8\u5e94\u7684\u4f9d\u8d56\u3002\u53ef\u4ee5\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\u4f7f\u7528<code>--hidden-import<\/code>\u9009\u9879\u6765\u5305\u542b\u90a3\u4e9b\u672a\u81ea\u52a8\u68c0\u6d4b\u5230\u7684\u5e93\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u5728\u5176\u4ed6\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u987a\u5229\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406Python\u7a0b\u5e8f\u4e2d\u7684\u5916\u90e8\u6587\u4ef6\u6216\u8d44\u6e90\uff1f<\/strong><br \/>\u5728\u5c06Python\u7a0b\u5e8f\u5c01\u88c5\u4e3aEXE\u65f6\uff0c\u5916\u90e8\u6587\u4ef6\uff08\u5982\u56fe\u50cf\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\u9700\u8981\u7279\u522b\u5904\u7406\u3002\u53ef\u4ee5\u4f7f\u7528PyInstaller\u7684<code>--add-data<\/code>\u9009\u9879\u6765\u5305\u62ec\u8fd9\u4e9b\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u547d\u4ee4\u683c\u5f0f\u4e3a<code>pyinstaller --onefile --add-data &quot;data.txt;.&quot; your_script.py<\/code>\u3002\u8fd9\u4f1a\u5c06<code>data.txt<\/code>\u6587\u4ef6\u5305\u542b\u5230EXE\u6587\u4ef6\u4e2d\uff0c\u5e76\u786e\u4fdd\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u8bbf\u95ee\u5230\u5b83\u3002\u8bb0\u5f97\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u6765\u5f15\u7528\u8fd9\u4e9b\u8d44\u6e90\uff0c\u4ee5\u907f\u514d\u8def\u5f84\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5c01\u88c5\u4e3aEXE\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u4f8b\u5982\uff1a\u4f7f\u7528PyInstaller\u3001cx_Freeze\u3001py2exe\u7b49\u5de5 [&hellip;]","protected":false},"author":3,"featured_media":1157518,"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\/1157513"}],"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=1157513"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1157513\/revisions"}],"predecessor-version":[{"id":1157519,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1157513\/revisions\/1157519"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1157518"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1157513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1157513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1157513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}