{"id":1038893,"date":"2024-12-31T12:27:58","date_gmt":"2024-12-31T04:27:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1038893.html"},"modified":"2024-12-31T12:28:01","modified_gmt":"2024-12-31T04:28:01","slug":"%e5%a6%82%e4%bd%95%e5%b0%86python%e4%bb%a3%e7%a0%81%e6%89%93%e5%8c%85%e6%88%90%e8%bd%af%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1038893.html","title":{"rendered":"\u5982\u4f55\u5c06python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/66ab2e6d-0fcb-47d5-ac21-eb535de67333.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u5c06python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\" \/><\/p>\n<p><p> <strong>\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528pyinstaller\u3001py2exe\u3001cx_Freeze\u7b49\u5de5\u5177<\/strong>\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5c06Python\u811a\u672c\u8f6c\u6362\u6210\u72ec\u7acb\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f7f\u5f97\u5373\u4f7f\u5728\u6ca1\u6709\u5b89\u88c5Python\u73af\u5883\u7684\u673a\u5668\u4e0a\u4e5f\u80fd\u8fd0\u884c\u3002<strong>pyinstaller\u662f\u6700\u5e38\u7528\u548c\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\u4e4b\u4e00<\/strong>\uff0c\u5b83\u652f\u6301\u591a\u5e73\u53f0\uff0c\u4f7f\u7528\u7b80\u5355\uff0c\u4e14\u53ef\u4ee5\u751f\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1apyinstaller\u7684\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528pyinstaller\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5pyinstaller\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06Python\u811a\u672c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pyinstaller --onefile your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2adist\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08your_script.exe\uff09\u3002\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6587\u4ef6\u5206\u53d1\u7ed9\u5176\u4ed6\u7528\u6237\uff0c\u65e0\u9700\u4ed6\u4eec\u5b89\u88c5Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u51c6\u5907\u5de5\u4f5c<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u6253\u5305\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684Python\u811a\u672c\u5728\u5f53\u524d\u73af\u5883\u4e2d\u8fd0\u884c\u6ca1\u6709\u95ee\u9898\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6216IDE\u8fd0\u884c\u4f60\u7684\u811a\u672c\uff0c\u786e\u4fdd\u5176\u6ca1\u6709\u9519\u8bef\uff0c\u5e76\u4e14\u6240\u6709\u4f9d\u8d56\u9879\u5df2\u7ecf\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u88c5\u4f9d\u8d56\u9879<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u811a\u672c\u4f7f\u7528\u4e86\u5916\u90e8\u5e93\u6216\u6a21\u5757\uff0c\u786e\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u9879\u5728\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528requirements.txt\u6587\u4ef6\u6765\u7ba1\u7406\u4f9d\u8d56\u9879\uff0c\u5e76\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4ee3\u7801\u6574\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305\u4e4b\u524d\uff0c\u6700\u597d\u5c06\u4ee3\u7801\u6574\u7406\u6210\u6a21\u5757\u5316\u7ed3\u6784\uff0c\u5e76\u786e\u4fdd\u5165\u53e3\u6587\u4ef6\uff08\u901a\u5e38\u662fm<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py\uff09\u660e\u786e\u3002\u8fd9\u6837\u5728\u6253\u5305\u65f6\uff0c\u53ef\u4ee5\u6e05\u6670\u5730\u6307\u5b9a\u5165\u53e3\u6587\u4ef6\uff0c\u907f\u514d\u6df7\u4e71\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528PyInstaller<\/h2>\n<\/p>\n<p><h3>\u5b89\u88c5PyInstaller<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5PyInstaller\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u57fa\u672c\u6253\u5305\u547d\u4ee4<\/h3>\n<\/p>\n<p><p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c06\u4f60\u7684Python\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pyinstaller --onefile your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2adist\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u4e86your_script.exe\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u5206\u53d1\u7ed9\u5176\u4ed6\u7528\u6237\u3002<\/p>\n<\/p>\n<p><h3>\u9ad8\u7ea7\u9009\u9879<\/h3>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528PyInstaller\u7684\u9ad8\u7ea7\u9009\u9879\u6765\u5b9a\u5236\u6253\u5305\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u56fe\u6807\uff0c\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\uff0c\u6dfb\u52a0\u989d\u5916\u7684\u6570\u636e\u6587\u4ef6\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pyinstaller --onefile --windowed --icon=app.ico your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a\u6ca1\u6709\u63a7\u5236\u53f0\u7a97\u53e3\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u6307\u5b9a\u7684\u56fe\u6807\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528cx_Freeze<\/h2>\n<\/p>\n<p><p>cx_Freeze\u662f\u53e6\u4e00\u4e2a\u5e38\u7528\u7684\u6253\u5305\u5de5\u5177\uff0c\u5b83\u652f\u6301\u591a\u5e73\u53f0\uff0c\u5e76\u4e14\u53ef\u4ee5\u751f\u6210Windows\u3001Mac\u548cLinux\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u88c5cx_Freeze<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5cx_Freeze\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install cx_Freeze<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7f16\u5199setup.py\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u8981\u4f7f\u7528cx_Freeze\u6253\u5305\u4f60\u7684Python\u811a\u672c\uff0c\u4f60\u9700\u8981\u7f16\u5199\u4e00\u4e2asetup.py\u6587\u4ef6\uff0c\u6307\u5b9a\u6253\u5305\u7684\u914d\u7f6e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\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;YourApp&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;, base=&quot;Win32GUI&quot;, icon=&quot;app.ico&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8fd0\u884c\u6253\u5305\u547d\u4ee4<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\u4f60\u7684\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">python setup.py build<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2abuild\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u548c\u6240\u6709\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528py2exe<\/h2>\n<\/p>\n<p><p>py2exe\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u5c06Python\u811a\u672c\u6253\u5305\u6210Windows\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u88c5py2exe<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5py2exe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7f16\u5199setup.py\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u8981\u4f7f\u7528py2exe\u6253\u5305\u4f60\u7684Python\u811a\u672c\uff0c\u4f60\u9700\u8981\u7f16\u5199\u4e00\u4e2asetup.py\u6587\u4ef6\uff0c\u6307\u5b9a\u6253\u5305\u7684\u914d\u7f6e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\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>    name=&quot;YourApp&quot;,<\/p>\n<p>    version=&quot;0.1&quot;,<\/p>\n<p>    description=&quot;Your App Description&quot;,<\/p>\n<p>    windows=[{&quot;script&quot;: &quot;your_script.py&quot;, &quot;icon_resources&quot;: [(1, &quot;app.ico&quot;)]}]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8fd0\u884c\u6253\u5305\u547d\u4ee4<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\u4f60\u7684\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">python setup.py py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2adist\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u4e86\u6253\u5305\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6\u548c\u6240\u6709\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/h2>\n<\/p>\n<p><h3>\u4f9d\u8d56\u9879\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4f9d\u8d56\u9879\u95ee\u9898\uff0c\u4f8b\u5982\u67d0\u4e9b\u5e93\u65e0\u6cd5\u6b63\u786e\u6253\u5305\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u89e3\u51b3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528&#8211;hidden-import\u53c2\u6570\u624b\u52a8\u6307\u5b9a\u4f9d\u8d56\u9879\u3002<\/li>\n<li>\u5728\u6253\u5305\u524d\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u90fd\u5df2\u5b89\u88c5\u3002<\/li>\n<li>\u68c0\u67e5\u6253\u5305\u5de5\u5177\u7684\u6587\u6863\uff0c\u4e86\u89e3\u5982\u4f55\u5904\u7406\u7279\u5b9a\u5e93\u7684\u4f9d\u8d56\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p><h3>\u6587\u4ef6\u8def\u5f84\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305\u540e\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6587\u4ef6\u8def\u5f84\u95ee\u9898\uff0c\u4f8b\u5982\u65e0\u6cd5\u627e\u5230\u67d0\u4e9b\u6570\u636e\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u89e3\u51b3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528PyInstaller\u7684&#8211;add-data\u53c2\u6570\u6dfb\u52a0\u6570\u636e\u6587\u4ef6\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528os.path\u6a21\u5757\u5904\u7406\u6587\u4ef6\u8def\u5f84\uff0c\u786e\u4fdd\u517c\u5bb9\u6027\u3002<\/li>\n<\/ul>\n<p><h3>\u8c03\u8bd5\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u8fdb\u884c\u8c03\u8bd5\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528PyInstaller\u7684&#8211;debug\u53c2\u6570\u751f\u6210\u8c03\u8bd5\u4fe1\u606f\u3002<\/li>\n<li>\u68c0\u67e5\u6253\u5305\u5de5\u5177\u751f\u6210\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u4e86\u89e3\u9519\u8bef\u539f\u56e0\u3002<\/li>\n<li>\u5728\u811a\u672c\u4e2d\u6dfb\u52a0\u8c03\u8bd5\u4fe1\u606f\uff0c\u5e2e\u52a9\u5b9a\u4f4d\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\u53ef\u4ee5\u4f7f\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u6613\u4e8e\u5206\u53d1\u548c\u4f7f\u7528\u3002\u901a\u8fc7\u4f7f\u7528PyInstaller\u3001cx_Freeze\u3001py2exe\u7b49\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Python\u811a\u672c\u8f6c\u6362\u6210\u72ec\u7acb\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<strong>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u8981\u6ce8\u610f\u4f9d\u8d56\u9879\u3001\u6587\u4ef6\u8def\u5f84\u7b49\u95ee\u9898\uff0c\u5e76\u4f7f\u7528\u9002\u5f53\u7684\u8c03\u8bd5\u65b9\u6cd5\u89e3\u51b3\u9047\u5230\u7684\u95ee\u9898<\/strong>\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u80fd\u6210\u529f\u5730\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\uff0c\u5e76\u987a\u5229\u5206\u53d1\u7ed9\u7528\u6237\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u6216cx_Freeze\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5c06Python\u811a\u672c\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u65e0\u9700\u5b89\u88c5Python\u73af\u5883\u5373\u53ef\u8fd0\u884c\u3002\u5b89\u88c5PyInstaller\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pyinstaller your_script.py<\/code>\u6765\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u751f\u6210\u7684\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e<code>dist<\/code>\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p><strong>\u6253\u5305Python\u5e94\u7528\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4f9d\u8d56\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u6253\u5305Python\u5e94\u7528\u65f6\uff0c\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5e93\u90fd\u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\u5305\u542b\u3002\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u53ef\u4ee5\u5e2e\u52a9\u7ba1\u7406\u4f9d\u8d56\u3002\u5728\u4f7f\u7528PyInstaller\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>--hidden-import<\/code>\u9009\u9879\u6dfb\u52a0\u672a\u88ab\u81ea\u52a8\u68c0\u6d4b\u5230\u7684\u4f9d\u8d56\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u4f7f\u7528\u7684\u5e93\u662f\u5426\u517c\u5bb9\u4e8e\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u4e3a\u6253\u5305\u540e\u7684Python\u8f6f\u4ef6\u6dfb\u52a0\u56fe\u6807\u548c\u5176\u4ed6\u8d44\u6e90\uff1f<\/strong><br \/>\u5728\u4f7f\u7528PyInstaller\u6253\u5305\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>--icon<\/code>\u9009\u9879\u4e3a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u6dfb\u52a0\u56fe\u6807\u3002\u4f8b\u5982\uff0c<code>pyinstaller --icon=your_icon.ico your_script.py<\/code>\u3002\u5982\u679c\u9700\u8981\u5305\u542b\u5176\u4ed6\u8d44\u6e90\u6587\u4ef6\uff08\u5982\u56fe\u7247\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\uff0c\u53ef\u4ee5\u5728.spec\u6587\u4ef6\u4e2d\u6307\u5b9a\uff0c\u6216\u8005\u4f7f\u7528<code>--add-data<\/code>\u9009\u9879\u5c06\u8fd9\u4e9b\u6587\u4ef6\u6253\u5305\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u7528\u6237\u5728\u8fd0\u884c\u8f6f\u4ef6\u65f6\uff0c\u6240\u6709\u6240\u9700\u7684\u8d44\u6e90\u90fd\u5df2\u5305\u542b\u5728\u5185\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u8f6f\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528pyinstaller\u3001py2exe\u3001cx_Freeze [&hellip;]","protected":false},"author":3,"featured_media":1038898,"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\/1038893"}],"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=1038893"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038893\/revisions"}],"predecessor-version":[{"id":1038900,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038893\/revisions\/1038900"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1038898"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1038893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1038893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1038893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}