{"id":931433,"date":"2024-12-26T17:36:18","date_gmt":"2024-12-26T09:36:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/931433.html"},"modified":"2024-12-26T17:36:21","modified_gmt":"2024-12-26T09:36:21","slug":"python%e5%a6%82%e4%bd%95%e5%8c%85%e8%a3%85exe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/931433.html","title":{"rendered":"python\u5982\u4f55\u5305\u88c5exe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065747\/25f6f10a-2470-4758-a4ca-cbdcd10cbc37.webp\" alt=\"python\u5982\u4f55\u5305\u88c5exe\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u5de5\u5177\u5c06\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u6709\u4f7f\u7528PyInstaller\u3001cx_Freeze\u3001py2exe\u7b49\u5de5\u5177\u3002<\/strong>\u5176\u4e2d\uff0c<strong>PyInstaller<\/strong> \u662f\u6700\u53d7\u6b22\u8fce\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u6613\u7528\uff0c\u652f\u6301\u591a\u79cd\u5e73\u53f0\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyInstaller\u5c06Python\u811a\u672c\u6253\u5305\u6210exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001PYINSTALLER\u7684\u5b89\u88c5\u4e0e\u57fa\u672c\u4f7f\u7528<\/p>\n<\/p>\n<p><p>PyInstaller \u662f\u4e00\u4e2a\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8eWindows\u3001Mac OS\u548cLinux\u7b49\u5e73\u53f0\u3002\u4f7f\u7528PyInstaller\u53ef\u4ee5\u5c06Python\u811a\u672c\u548c\u5176\u4f9d\u8d56\u7684\u5e93\u3001\u6570\u636e\u6587\u4ef6\u7b49\u6253\u5305\u5728\u4e00\u8d77\uff0c\u5f62\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65e0\u9700\u7528\u6237\u5b89\u88c5Python\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5PyInstaller<\/li>\n<\/ol>\n<p><p>\u8981\u4f7f\u7528PyInstaller\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u73af\u5883\u4e2d\u5b89\u88c5\u4e86\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\u5b89\u88c5\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\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>pyinstaller<\/code>\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528PyInstaller\u6253\u5305<\/li>\n<\/ol>\n<p><p>PyInstaller\u7684\u57fa\u672c\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\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>\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPyInstaller\u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u3002\u5982\u679c\u9700\u8981\u751f\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--onefile<\/code>\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001PYINSTALLER\u7684\u9ad8\u7ea7\u9009\u9879\u4e0e\u914d\u7f6e<\/p>\n<\/p>\n<p><p>PyInstaller\u4e0d\u4ec5\u53ef\u4ee5\u7b80\u5355\u5730\u6253\u5305Python\u811a\u672c\uff0c\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u9009\u9879\u548c\u914d\u7f6e\u529f\u80fd\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6dfb\u52a0\u56fe\u6807\u548c\u7248\u672c\u4fe1\u606f<\/li>\n<\/ol>\n<p><p>\u5728\u6253\u5305\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u4e3a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u6dfb\u52a0\u56fe\u6807\u548c\u7248\u672c\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7<code>--icon<\/code>\u9009\u9879\u6307\u5b9a\u4e00\u4e2a.ico\u683c\u5f0f\u7684\u56fe\u6807\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --icon=your_icon.ico your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u540c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00\u4e2a.spec\u6587\u4ef6\u6765\u6307\u5b9a\u7248\u672c\u4fe1\u606f\u3002spec\u6587\u4ef6\u662fPyInstaller\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5141\u8bb8\u7528\u6237\u5bf9\u6253\u5305\u8fc7\u7a0b\u8fdb\u884c\u7cbe\u7ec6\u63a7\u5236\u3002\u5728.spec\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3001\u7248\u672c\u53f7\u3001\u7248\u6743\u4fe1\u606f\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5305\u542b\u6570\u636e\u6587\u4ef6\u548c\u4f9d\u8d56\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0cPython\u811a\u672c\u53ef\u80fd\u9700\u8981\u4f9d\u8d56\u5916\u90e8\u7684\u6570\u636e\u6587\u4ef6\u6216\u5e93\uff0c\u8fd9\u4e9b\u6587\u4ef6\u4e5f\u9700\u8981\u88ab\u5305\u542b\u5728\u6253\u5305\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002PyInstaller\u63d0\u4f9b\u4e86<code>--add-data<\/code>\u9009\u9879\uff0c\u53ef\u4ee5\u5c06\u6307\u5b9a\u7684\u6570\u636e\u6587\u4ef6\u5305\u542b\u8fdb\u53bb\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --add-data &quot;datafile.txt;.&quot; your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>--add-data<\/code>\u9009\u9879\u4f7f\u7528\u4e86\u4e00\u4e2a\u5206\u53f7\uff08;\uff09\u6765\u5206\u9694\u6e90\u6587\u4ef6\u8def\u5f84\u548c\u76ee\u6807\u76ee\u5f55\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u8bbe\u7f6e\u5165\u53e3\u6587\u4ef6\u548c\u9690\u85cf\u63a7\u5236\u53f0<\/li>\n<\/ol>\n<p><p>\u5728\u6253\u5305GUI\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u901a\u5e38\u4e0d\u5e0c\u671b\u663e\u793a\u63a7\u5236\u53f0\u7a97\u53e3\u3002\u53ef\u4ee5\u901a\u8fc7<code>--noconsole<\/code>\u9009\u9879\u6765\u9690\u85cf\u63a7\u5236\u53f0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --noconsole your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u9879\u76ee\u6709\u591a\u4e2aPython\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>--name<\/code>\u9009\u9879\u6307\u5b9a\u5165\u53e3\u6587\u4ef6\u548c\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u540d\u79f0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --name=your_app_name your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001CX_FREEZE\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>cx_Freeze\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u5c06Python\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5b83\u5177\u6709\u826f\u597d\u7684\u517c\u5bb9\u6027\uff0c\u652f\u6301Python 3.x\u7248\u672c\uff0c\u5e76\u4e14\u53ef\u4ee5\u6253\u5305Windows\u548cLinux\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5cx_Freeze<\/li>\n<\/ol>\n<p><p>\u4e0ePyInstaller\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\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<ol start=\"2\">\n<li>\u4f7f\u7528cx_Freeze\u6253\u5305<\/li>\n<\/ol>\n<p><p>cx_Freeze\u901a\u5e38\u9700\u8981\u7f16\u5199\u4e00\u4e2asetup\u811a\u672c\u6765\u6307\u5b9a\u6253\u5305\u7684\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684setup\u811a\u672c\u793a\u4f8b\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;your_app_name&quot;,<\/p>\n<p>    version=&quot;0.1&quot;,<\/p>\n<p>    description=&quot;Your application 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>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5f00\u59cb\u6253\u5305\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>\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>build<\/code>\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u6dfb\u52a0\u989d\u5916\u7684\u9009\u9879<\/li>\n<\/ol>\n<p><p>\u5728setup\u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>options<\/code>\u53c2\u6570\u6765\u6dfb\u52a0\u989d\u5916\u7684\u6253\u5305\u9009\u9879\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5305\u542b\u989d\u5916\u7684\u6a21\u5757\u6216\u6392\u9664\u67d0\u4e9b\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">options={<\/p>\n<p>    &quot;build_exe&quot;: {<\/p>\n<p>        &quot;packages&quot;: [&quot;os&quot;, &quot;sys&quot;],<\/p>\n<p>        &quot;excludes&quot;: [&quot;tkinter&quot;]<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001PY2EXE\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>py2exe\u662f\u4e13\u95e8\u7528\u4e8e\u5c06Python\u811a\u672c\u6253\u5305\u6210Windows\u5e73\u53f0\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u4e0d\u8fc7\uff0cpy2exe\u53ea\u652f\u6301Python 2.x\u7248\u672c\uff0c\u5bf9Python 3.x\u7684\u652f\u6301\u6709\u9650\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5py2exe<\/li>\n<\/ol>\n<p><p>\u540c\u6837\u5730\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\u5b89\u88c5py2exe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528py2exe\u6253\u5305<\/li>\n<\/ol>\n<p><p>py2exe\u4e5f\u9700\u8981\u4e00\u4e2asetup\u811a\u672c\u6765\u6307\u5b9a\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684setup\u811a\u672c\u793a\u4f8b\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>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5f00\u59cb\u6253\u5305\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>\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u914d\u7f6e\u9ad8\u7ea7\u9009\u9879<\/li>\n<\/ol>\n<p><p>\u5728setup\u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>options<\/code>\u53c2\u6570\u6765\u6dfb\u52a0\u9ad8\u7ea7\u9009\u9879\uff0c\u4f8b\u5982\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\u3001\u5305\u542b\u989d\u5916\u7684\u6a21\u5757\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">options={<\/p>\n<p>    &quot;py2exe&quot;: {<\/p>\n<p>        &quot;bundle_files&quot;: 1,<\/p>\n<p>        &quot;compressed&quot;: True<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6253\u5305\u65f6\u7684\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u6253\u5305Python\u811a\u672c\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\uff0c\u5982\u6253\u5305\u540e\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c\u3001\u627e\u4e0d\u5230\u6a21\u5757\u3001\u56fe\u6807\u6216\u6570\u636e\u6587\u4ef6\u4e22\u5931\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<ol>\n<li>\u65e0\u6cd5\u627e\u5230\u6a21\u5757<\/li>\n<\/ol>\n<p><p>\u6253\u5305\u540e\u7a0b\u5e8f\u65e0\u6cd5\u627e\u5230\u67d0\u4e9b\u6a21\u5757\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u8fd9\u4e9b\u6a21\u5757\u6ca1\u6709\u88ab\u6b63\u786e\u5730\u5305\u542b\u5728\u6253\u5305\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0<code>--hidden-import<\/code>\u9009\u9879\u6765\u624b\u52a8\u6307\u5b9a\u9700\u8981\u5305\u542b\u7684\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --hidden-import=module_name your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6253\u5305\u540e\u7684\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c<\/li>\n<\/ol>\n<p><p>\u5982\u679c\u6253\u5305\u540e\u7684\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u7f3a\u5c11\u4e00\u4e9b\u5fc5\u8981\u7684\u4f9d\u8d56\u5e93\u6216\u6570\u636e\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u6253\u5305\u65e5\u5fd7\u6765\u67e5\u627e\u7f3a\u5931\u7684\u6587\u4ef6\u6216\u5e93\uff0c\u5e76\u624b\u52a8\u6dfb\u52a0\u5b83\u4eec\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u56fe\u6807\u6216\u6570\u636e\u6587\u4ef6\u4e22\u5931<\/li>\n<\/ol>\n<p><p>\u5982\u679c\u6253\u5305\u540e\u7684\u7a0b\u5e8f\u4e2d\u7f3a\u5c11\u56fe\u6807\u6216\u6570\u636e\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5.spec\u6587\u4ef6\u6216setup\u811a\u672c\u7684\u914d\u7f6e\u6765\u786e\u4fdd\u8fd9\u4e9b\u6587\u4ef6\u88ab\u6b63\u786e\u5730\u5305\u542b\u5728\u6253\u5305\u7684\u8fc7\u7a0b\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5c06Python\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u662fPython\u5f00\u53d1\u4e2d\u4e00\u4e2a\u91cd\u8981\u7684\u73af\u8282\u3002\u901a\u8fc7\u4f7f\u7528PyInstaller\u3001cx_Freeze\u548cpy2exe\u7b49\u5de5\u5177\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65b9\u4fbf\u5206\u53d1\u548c\u53d1\u5e03\u3002\u6bcf\u79cd\u5de5\u5177\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u7684\u573a\u666f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u8fdb\u884c\u6253\u5305\u3002\u5728\u6253\u5305\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u6b63\u786e\u914d\u7f6e\u76f8\u5173\u9009\u9879\uff0c\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u6a21\u5757\u548c\u6587\u4ef6\u88ab\u5305\u542b\u5728\u6253\u5305\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\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 \/>\u5c06Python\u811a\u672c\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u3001cx_Freeze\u6216py2exe\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5c06\u4f60\u7684Python\u4ee3\u7801\u548c\u4f9d\u8d56\u9879\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u65e0\u9700\u5b89\u88c5Python\u73af\u5883\u4e5f\u80fd\u8fd0\u884c\u3002\u4f7f\u7528PyInstaller\u65f6\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u8f93\u5165<code>pyinstaller your_script.py<\/code>\uff0c\u7cfb\u7edf\u4f1a\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p><strong>\u4f7f\u7528PyInstaller\u6253\u5305exe\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u4f7f\u7528PyInstaller\u6253\u5305\u65f6\uff0c\u786e\u4fdd\u5728\u4f60\u7684\u811a\u672c\u4e2d\u6ca1\u6709\u786c\u7f16\u7801\u7684\u8def\u5f84\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u6240\u6709\u5916\u90e8\u6587\u4ef6\uff08\u5982\u56fe\u7247\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\u662f\u5426\u88ab\u6b63\u786e\u5305\u542b\u3002\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>--onefile<\/code>\u9009\u9879\u6765\u521b\u5efa\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f46\u8fd9\u53ef\u80fd\u4f1a\u589e\u52a0\u542f\u52a8\u65f6\u95f4\u3002\u6d4b\u8bd5\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u7684\u8fd0\u884c\u60c5\u51b5\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u5728\u5176\u4ed6\u7535\u8111\u4e0a\u80fd\u6b63\u5e38\u8fd0\u884c\u5417\uff1f<\/strong><br \/>\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u53ef\u4ee5\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u7535\u8111\u4e0a\u8fd0\u884c\uff0c\u4f46\u9700\u786e\u4fdd\u76ee\u6807\u7535\u8111\u62e5\u6709\u5fc5\u8981\u7684\u7cfb\u7edf\u5e93\u548c\u4f9d\u8d56\u9879\u3002\u5982\u679c\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u6709\u7279\u5b9a\u7684\u4f9d\u8d56\uff0c\u5efa\u8bae\u5728\u76ee\u6807\u7535\u8111\u4e0a\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u5e93\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u4f7f\u7528\u7684\u662f\u4e0e\u76ee\u6807\u7535\u8111\u76f8\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u67b6\u6784\uff0832\u4f4d\u621664\u4f4d\uff09\u3002\u4e3a\u4e86\u786e\u4fdd\u517c\u5bb9\u6027\uff0c\u6700\u597d\u5728\u76ee\u6807\u7cfb\u7edf\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u5de5\u5177\u5c06\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u6709\u4f7f\u7528PyInstaller\u3001cx_F [&hellip;]","protected":false},"author":3,"featured_media":931440,"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\/931433"}],"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=931433"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/931433\/revisions"}],"predecessor-version":[{"id":931441,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/931433\/revisions\/931441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/931440"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=931433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=931433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=931433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}