{"id":1116254,"date":"2025-01-08T18:14:46","date_gmt":"2025-01-08T10:14:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1116254.html"},"modified":"2025-01-08T18:14:48","modified_gmt":"2025-01-08T10:14:48","slug":"python3%e5%a6%82%e4%bd%95%e6%89%93%e5%8c%85%e6%88%90%e5%ae%89%e8%a3%85%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1116254.html","title":{"rendered":"Python3\u5982\u4f55\u6253\u5305\u6210\u5b89\u88c5\u7a0b\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080653\/e634d314-075d-4e97-87dd-cb870b98ccb9.webp\" alt=\"Python3\u5982\u4f55\u6253\u5305\u6210\u5b89\u88c5\u7a0b\u5e8f\" \/><\/p>\n<p><p> <strong>Python3\u6253\u5305\u6210\u5b89\u88c5\u7a0b\u5e8f<\/strong>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u5e38\u7528\u65b9\u6cd5\uff1a\u4f7f\u7528PyInstaller\u3001\u4f7f\u7528cx_Freeze\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u548c\u4f7f\u7528pip\u5b89\u88c5\u4f9d\u8d56\u3002<strong>PyInstaller\u3001cx_Freeze\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\u662f\u5e38\u7528\u65b9\u6cd5\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>PyInstaller \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06 Python \u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5b83\u652f\u6301 Windows\u3001macOS \u548c Linux \u5e73\u53f0\uff0c\u53ef\u4ee5\u5904\u7406\u590d\u6742\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4e14\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5305\u542b\u6240\u6709\u5fc5\u8981\u7684\u5e93\u548c\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5PyInstaller<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528PyInstaller\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u8fdb\u884c\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\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528 <code>pyinstaller<\/code> \u547d\u4ee4\u6765\u6253\u5305Python\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u7b80\u5355\u7684Python\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>hello.py<\/code> \u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528PyInstaller\u6253\u5305<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u5305\u542b <code>hello.py<\/code> \u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542b\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u3002<code>--onefile<\/code> \u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u5185\u5bb9\u6253\u5305\u6210\u4e00\u4e2a\u5355\u4e00\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u68c0\u67e5\u6253\u5305\u7ed3\u679c<\/h4>\n<\/p>\n<p><p>\u6253\u5305\u5b8c\u6210\u540e\uff0cPyInstaller \u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a <code>dist<\/code> \u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728 <code>dist<\/code> \u76ee\u5f55\u4e2d\u627e\u5230 <code>hello<\/code> \u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">.\/dist\/hello<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u65f6\u5e94\u8be5\u4f1a\u5728\u7ec8\u7aef\u4e2d\u770b\u5230 <code>Hello, World!<\/code> \u7684\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u6253\u5305\u9009\u9879<\/h3>\n<\/p>\n<p><p>PyInstaller \u63d0\u4f9b\u4e86\u8bb8\u591a\u914d\u7f6e\u9009\u9879\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u8c03\u6574\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u6307\u5b9a\u5165\u53e3\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u6307\u5b9a\u8981\u6253\u5305\u7684\u5165\u53e3\u811a\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bbe\u7f6e\u8f93\u51fa\u76ee\u5f55<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>--distpath<\/code> \u9009\u9879\u8bbe\u7f6e\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8f93\u51fa\u76ee\u5f55\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --distpath .\/output my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u6dfb\u52a0\u56fe\u6807<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>--icon<\/code> \u9009\u9879\u4e3a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u6dfb\u52a0\u56fe\u6807\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --icon=my_icon.ico my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8eGUI\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>--noconsole<\/code> \u9009\u9879\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --noconsole my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u4f9d\u8d56\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0cPyInstaller \u4f1a\u81ea\u52a8\u68c0\u6d4b\u5e76\u5305\u542b\u5927\u591a\u6570\u4f9d\u8d56\u9879\u3002\u4f46\u662f\uff0c\u6709\u65f6\u9700\u8981\u624b\u52a8\u6307\u5b9a\u989d\u5916\u7684\u4f9d\u8d56\u9879\u6216\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5305\u542b\u989d\u5916\u7684\u4f9d\u8d56\u9879<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>--hidden-import<\/code> \u9009\u9879\u624b\u52a8\u6307\u5b9a\u989d\u5916\u7684\u4f9d\u8d56\u9879\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --hidden-import=some_module my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6dfb\u52a0\u8d44\u6e90\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>--add-data<\/code> \u9009\u9879\u6dfb\u52a0\u989d\u5916\u7684\u8d44\u6e90\u6587\u4ef6\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --add-data=&quot;data_file.txt;.&quot; my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5305Python\u7a0b\u5e8f\u4e4b\u524d\uff0c\u5efa\u8bae\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u4ee5\u786e\u4fdd\u4f9d\u8d56\u9879\u7684\u9694\u79bb\u548c\u7ba1\u7406\u3002\u4ee5\u4e0b\u662f\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528 <code>venv<\/code> \u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u4f8b\u5982\uff0c\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>venv<\/code> \u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u540c\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u7565\u6709\u4e0d\u540c\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">venv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li>\u5728macOS\u548cLinux\u4e0a\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">source venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528pip\u5b89\u88c5\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002\u786e\u4fdd\u5728 <code>requirements.txt<\/code> \u6587\u4ef6\u4e2d\u5217\u51fa\u6240\u6709\u4f9d\u8d56\u9879\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u793a\u4f8b\u9879\u76ee<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u9879\u76ee\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528PyInstaller\u6253\u5305\u4e00\u4e2a\u5305\u542b\u4f9d\u8d56\u9879\u548c\u8d44\u6e90\u6587\u4ef6\u7684Python\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u9879\u76ee\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u9879\u76ee\u7ed3\u6784\uff1a<\/p>\n<\/p>\n<p><pre><code>my_project\/<\/p>\n<p>\u251c\u2500\u2500 my_script.py<\/p>\n<p>\u251c\u2500\u2500 requirements.txt<\/p>\n<p>\u251c\u2500\u2500 data\/<\/p>\n<p>\u2502   \u2514\u2500\u2500 data_file.txt<\/p>\n<p>\u2514\u2500\u2500 venv\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7f16\u5199\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728 <code>my_script.py<\/code> \u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u8bfb\u53d6\u8d44\u6e90\u6587\u4ef6\u5e76\u6253\u5370\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>with open(os.path.join(&#39;data&#39;, &#39;data_file.txt&#39;), &#39;r&#39;) as f:<\/p>\n<p>    content = f.read()<\/p>\n<p>print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5217\u51fa\u4f9d\u8d56\u9879<\/h4>\n<\/p>\n<p><p>\u5728 <code>requirements.txt<\/code> \u4e2d\u5217\u51fa\u6240\u9700\u7684\u4f9d\u8d56\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code># \u793a\u4f8b\u4f9d\u8d56\u9879<\/p>\n<h2><strong>requests==2.25.1<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u5b89\u88c5\u4f9d\u8d56<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u6fc0\u6d3b\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv venv<\/p>\n<p>source venv\/bin\/activate  # \u5728Windows\u4e0a\u4f7f\u7528 `venv\\Scripts\\activate`<\/p>\n<p>pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u4f7f\u7528PyInstaller\u6253\u5305<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --add-data=&quot;data\/data_file.txt;data&quot; my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5c06\u5728 <code>dist<\/code> \u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u8fd0\u884c\u5b83\u5e76\u9a8c\u8bc1\u6253\u5305\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001cx_Freeze<\/h3>\n<\/p>\n<p><p>\u9664\u4e86PyInstaller\u4e4b\u5916\uff0ccx_Freeze\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u6253\u5305\u5de5\u5177\u3002\u5b83\u652f\u6301\u591a\u5e73\u53f0\uff0c\u53ef\u4ee5\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5cx_Freeze<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7pip\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>2\u3001\u521b\u5efasetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>setup.py<\/code> \u7684\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;my_script&quot;,<\/p>\n<p>    version=&quot;1.0&quot;,<\/p>\n<p>    description=&quot;My Python Application&quot;,<\/p>\n<p>    executables=[Executable(&quot;my_script.py&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u8fd0\u884csetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u4f7f\u7528cx_Freeze\u8fdb\u884c\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>\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5c06\u5728 <code>build<\/code> \u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u8fd0\u884c\u5b83\u5e76\u9a8c\u8bc1\u6253\u5305\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528PyInstaller\u548ccx_Freeze\u5c06Python3\u7a0b\u5e8f\u6253\u5305\u6210\u5b89\u88c5\u7a0b\u5e8f\u3002<strong>PyInstaller\u3001cx_Freeze\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u4f7f\u7528pip\u5b89\u88c5\u4f9d\u8d56<\/strong>\u90fd\u662f\u5e38\u7528\u7684\u6253\u5305\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u60a8\u5728Python\u5e94\u7528\u7a0b\u5e8f\u7684\u6253\u5305\u8fc7\u7a0b\u4e2d\u987a\u5229\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python3\u9879\u76ee\u6253\u5305\u6210\u53ef\u6267\u884c\u7684\u5b89\u88c5\u7a0b\u5e8f\uff1f<\/strong><br \/>\u8981\u5c06Python3\u9879\u76ee\u6253\u5305\u6210\u53ef\u6267\u884c\u7684\u5b89\u88c5\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u3001cx_Freeze\u6216py2exe\u3002\u8fd9\u4e9b\u5de5\u5177\u80fd\u591f\u5c06Python\u4ee3\u7801\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u53ea\u9700\u8fd0\u884c\u8be5\u6587\u4ef6\u5373\u53ef\u4f7f\u7528\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5177\u4f53\u6b65\u9aa4\u901a\u5e38\u5305\u62ec\uff1a\u5b89\u88c5\u6253\u5305\u5de5\u5177\u3001\u7f16\u5199\u6253\u5305\u914d\u7f6e\u6587\u4ef6\u3001\u8fd0\u884c\u6253\u5305\u547d\u4ee4\uff0c\u5e76\u6d4b\u8bd5\u751f\u6210\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002<\/p>\n<p><strong>\u5728\u6253\u5305Python3\u7a0b\u5e8f\u65f6\uff0c\u5982\u4f55\u5904\u7406\u4f9d\u8d56\u5e93\uff1f<\/strong><br \/>\u6253\u5305Python3\u7a0b\u5e8f\u65f6\uff0c\u5904\u7406\u4f9d\u8d56\u5e93\u81f3\u5173\u91cd\u8981\u3002\u5927\u591a\u6570\u6253\u5305\u5de5\u5177\u4f1a\u81ea\u52a8\u8bc6\u522b\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u5e93\u5e76\u5c06\u5176\u5305\u542b\u5728\u5185\u3002\u4f46\u662f\uff0c\u5efa\u8bae\u5728\u6253\u5305\u4e4b\u524d\uff0c\u901a\u8fc7requirements.txt\u6587\u4ef6\u660e\u786e\u5217\u51fa\u6240\u6709\u4f9d\u8d56\uff0c\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u5e93\u90fd\u88ab\u6b63\u786e\u6253\u5305\u3002\u5728\u4f7f\u7528PyInstaller\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--hidden-import<\/code>\u9009\u9879\u6765\u624b\u52a8\u6307\u5b9a\u672a\u88ab\u81ea\u52a8\u68c0\u6d4b\u5230\u7684\u4f9d\u8d56\u3002<\/p>\n<p><strong>\u6253\u5305\u540e\u7684\u5b89\u88c5\u7a0b\u5e8f\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u80fd\u5426\u901a\u7528\uff1f<\/strong><br \/>\u6253\u5305\u540e\u7684\u5b89\u88c5\u7a0b\u5e8f\u901a\u5e38\u662f\u9488\u5bf9\u7279\u5b9a\u64cd\u4f5c\u7cfb\u7edf\u751f\u6210\u7684\u3002\u4f8b\u5982\uff0c\u5728Windows\u4e0a\u6253\u5305\u7684\u5e94\u7528\u7a0b\u5e8f\u65e0\u6cd5\u76f4\u63a5\u5728Linux\u6216MacOS\u4e0a\u8fd0\u884c\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5e0c\u671b\u5728\u591a\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u53d1\u5e03\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u9700\u8981\u5206\u522b\u5728\u6bcf\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u6253\u5305\u5de5\u5177\u4ee5\u751f\u6210\u76f8\u5e94\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u8fd9\u610f\u5473\u7740\u53ef\u80fd\u9700\u8981\u9488\u5bf9\u4e0d\u540c\u5e73\u53f0\u7684\u4ee3\u7801\u548c\u4f9d\u8d56\u9879\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python3\u6253\u5305\u6210\u5b89\u88c5\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u5e38\u7528\u65b9\u6cd5\uff1a\u4f7f\u7528PyInstaller\u3001\u4f7f\u7528cx_Freeze\u3001\u521b\u5efa [&hellip;]","protected":false},"author":3,"featured_media":1116261,"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\/1116254"}],"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=1116254"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1116254\/revisions"}],"predecessor-version":[{"id":1116262,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1116254\/revisions\/1116262"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1116261"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1116254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1116254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1116254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}