{"id":1095452,"date":"2025-01-08T14:51:15","date_gmt":"2025-01-08T06:51:15","guid":{"rendered":""},"modified":"2025-01-08T14:51:30","modified_gmt":"2025-01-08T06:51:30","slug":"%e5%a6%82%e4%bd%95%e6%8a%8apython%e6%96%87%e4%bb%b6%e8%bd%ac%e5%8c%96%e4%b8%baexe%e6%96%87%e4%bb%b6-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1095452.html","title":{"rendered":"\u5982\u4f55\u628apython\u6587\u4ef6\u8f6c\u5316\u4e3aexe\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211112\/9b704881-d69d-42cd-a36a-4c81501d805d.webp\" alt=\"\u5982\u4f55\u628apython\u6587\u4ef6\u8f6c\u5316\u4e3aexe\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u628aPython\u6587\u4ef6\u8f6c\u5316\u4e3aexe\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u3001cx_Freeze\u3001Py2exe\u3001py2app\u3001\u786e\u4fddPython\u73af\u5883\u914d\u7f6e\u6b63\u786e<\/strong>\u3001<strong>\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u6ce8\u610f\u4f9d\u8d56\u5305\u7684\u5904\u7406\u3001\u8fdb\u884c\u6b63\u786e\u7684\u6253\u5305\u547d\u4ee4\u914d\u7f6e<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002PyInstaller\u662f\u4e00\u4e2a\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u3002\u5b83\u53ef\u4ee5\u5206\u6790Python\u7a0b\u5e8f\u7684\u6240\u6709\u4f9d\u8d56\uff0c\u5e76\u5c06\u5b83\u4eec\u6253\u5305\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002\u8fd9\u6837\uff0c\u7528\u6237\u5728\u8fd0\u884c\u4f60\u7684\u7a0b\u5e8f\u65f6\uff0c\u65e0\u9700\u518d\u5b89\u88c5Python\u89e3\u91ca\u5668\u6216\u5176\u4ed6\u4f9d\u8d56\u5305\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyInstaller\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u786e\u4fddPython\u73af\u5883\u914d\u7f6e\u6b63\u786e<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u8f6c\u6362\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u5df2\u7ecf\u6b63\u786e\u914d\u7f6e\uff0c\u5e76\u4e14\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\u5df2\u7ecf\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u786e\u8ba4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u68c0\u67e5Python\u7248\u672c\uff1a\u786e\u4fdd\u4f60\u4f7f\u7528\u7684\u662fPython 3.x\u7248\u672c\uff0c\u56e0\u4e3a\u5927\u591a\u6570\u73b0\u4ee3\u5de5\u5177\u548c\u5e93\u90fd\u9700\u8981Python 3.x\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5pip\uff1apip\u662fPython\u7684\u5305\u7ba1\u7406\u5668\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5pip\u662f\u5426\u5df2\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5pip\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m ensurepip --default-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\uff1a\u6839\u636e\u4f60\u7684Python\u9879\u76ee\u7684\u9700\u6c42\uff0c\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5\u8fd9\u4e9b\u5305\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests pandas numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528PyInstaller\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5PyInstaller\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5PyInstaller\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5PyInstaller\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884cPyInstaller\uff1a\u5728\u5b89\u88c5\u5b8cPyInstaller\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u4f60\u7684Python\u811a\u672c\u6240\u5728\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 your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>your_script.py<\/code>\u662f\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\u540d\u3002<code>--onefile<\/code>\u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u751f\u6210\u7684exe\u6587\u4ef6\uff1a\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0cPyInstaller\u4f1a\u5728\u4f60\u7684\u811a\u672c\u6240\u5728\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u4e86\u751f\u6210\u7684exe\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u5728<code>dist<\/code>\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u4f60\u7684exe\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u6ce8\u610f\u4f9d\u8d56\u5305\u7684\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5904\u7406\u4f9d\u8d56\u5305\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6b65\u9aa4\u3002PyInstaller\u4f1a\u81ea\u52a8\u5206\u6790\u4f60\u7684\u811a\u672c\u6587\u4ef6\u5e76\u627e\u51fa\u6240\u6709\u7684\u4f9d\u8d56\u5305\uff0c\u4f46\u662f\u6709\u65f6\u5019\u5b83\u53ef\u80fd\u4f1a\u9057\u6f0f\u4e00\u4e9b\u5305\u3002\u4e3a\u4e86\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5305\u90fd\u88ab\u6b63\u786e\u6253\u5305\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u4f7f\u7528\u9690\u85cf\u5bfc\u5165\u9009\u9879\uff1a\u5982\u679c\u4f60\u77e5\u9053\u67d0\u4e2a\u4f9d\u8d56\u5305\u6ca1\u6709\u88ab\u81ea\u52a8\u6253\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--hidden-import<\/code>\u9009\u9879\u624b\u52a8\u6307\u5b9a\u5b83\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --hidden-import=missing_package your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u4f9d\u8d56\u5305\u5217\u8868\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u751f\u6210\u7684<code>your_script.spec<\/code>\u6587\u4ef6\u6765\u68c0\u67e5\u6240\u6709\u7684\u4f9d\u8d56\u5305\uff0c\u5e76\u624b\u52a8\u6dfb\u52a0\u9057\u6f0f\u7684\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u8fdb\u884c\u6b63\u786e\u7684\u6253\u5305\u547d\u4ee4\u914d\u7f6e<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305\u65f6\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u4e0d\u540c\u7684\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u56fe\u6807\u6587\u4ef6\u3001\u7981\u7528\u63a7\u5236\u53f0\u7a97\u53e3\u3001\u6dfb\u52a0\u989d\u5916\u7684\u6587\u4ef6\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u914d\u7f6e\u9009\u9879\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6307\u5b9a\u56fe\u6807\u6587\u4ef6\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528<code>--icon<\/code>\u9009\u9879\u6307\u5b9aexe\u6587\u4ef6\u7684\u56fe\u6807\uff0c\u4f8b\u5982\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<\/li>\n<li>\n<p>\u7981\u7528\u63a7\u5236\u53f0\u7a97\u53e3\uff1a\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u662f\u4e00\u4e2a\u56fe\u5f62\u754c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--noconsole<\/code>\u9009\u9879\u7981\u7528\u63a7\u5236\u53f0\u7a97\u53e3\uff0c\u4f8b\u5982\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<\/li>\n<li>\n<p>\u6dfb\u52a0\u989d\u5916\u7684\u6587\u4ef6\uff1a\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u989d\u5916\u7684\u6587\u4ef6\uff08\u5982\u6570\u636e\u6587\u4ef6\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\uff0c\u53ef\u4ee5\u5728.spec\u6587\u4ef6\u4e2d\u624b\u52a8\u6dfb\u52a0\u8fd9\u4e9b\u6587\u4ef6\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = Analysis([&#39;your_script.py&#39;],<\/p>\n<p>             pathex=[&#39;\/path\/to\/your\/script&#39;],<\/p>\n<p>             binaries=[],<\/p>\n<p>             datas=[(&#39;data_file.txt&#39;, &#39;destination_folder&#39;)])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5176\u4ed6\u5e38\u7528\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u9664\u4e86PyInstaller\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5de5\u5177\u53ef\u4ee5\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>cx_Freeze\uff1acx_Freeze\u662f\u53e6\u4e00\u4e2a\u5c06Python\u811a\u672c\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u652f\u6301Windows\u3001Mac\u548cLinux\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7pip\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><p>\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cxfreeze your_script.py --target-dir dist<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>Py2exe\uff1aPy2exe\u662f\u4e00\u4e2a\u5c06Python\u811a\u672c\u6253\u5305\u4e3aWindows\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8eWindows\u5e73\u53f0\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7pip\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><p>\u7136\u540e\u521b\u5efa\u4e00\u4e2asetup.py\u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\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<\/li>\n<li>\n<p>py2app\uff1apy2app\u662f\u4e00\u4e2a\u5c06Python\u811a\u672c\u6253\u5305\u4e3aMac\u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8eMac\u5e73\u53f0\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5py2app\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install py2app<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u521b\u5efa\u4e00\u4e2asetup.py\u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py py2app<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u6253\u5305\u540e\u7684\u6d4b\u8bd5\u548c\u5206\u53d1<\/p>\n<\/p>\n<p><p>\u5728\u6210\u529f\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u540e\uff0c\u63a5\u4e0b\u6765\u9700\u8981\u8fdb\u884c\u6d4b\u8bd5\u548c\u5206\u53d1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6d4b\u8bd5exe\u6587\u4ef6\uff1a\u5728\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u751f\u6210\u7684exe\u6587\u4ef6\uff0c\u786e\u4fdd\u5b83\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\uff0c\u5e76\u4e14\u6240\u6709\u529f\u80fd\u90fd\u80fd\u5982\u9884\u671f\u8fd0\u884c\u3002\u7279\u522b\u6ce8\u610f\u90a3\u4e9b\u4f9d\u8d56\u4e8e\u7279\u5b9a\u64cd\u4f5c\u7cfb\u7edf\u6216\u786c\u4ef6\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5e38\u89c1\u95ee\u9898\uff1a\u5728\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u53d1\u73b0\u95ee\u9898\uff0c\u53ef\u4ee5\u53c2\u8003PyInstaller\u6216\u5176\u4ed6\u5de5\u5177\u7684\u6587\u6863\u548c\u793e\u533a\u652f\u6301\uff0c\u5bfb\u627e\u89e3\u51b3\u65b9\u6848\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u4f9d\u8d56\u5305\u7f3a\u5931\u3001\u8def\u5f84\u9519\u8bef\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u5b89\u88c5\u7a0b\u5e8f\uff1a\u5982\u679c\u4f60\u5e0c\u671b\u7528\u6237\u80fd\u591f\u65b9\u4fbf\u5730\u5b89\u88c5\u4f60\u7684\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b89\u88c5\u7a0b\u5e8f\u521b\u5efa\u5de5\u5177\uff08\u5982Inno Setup\u3001NSIS\u3001InstallShield\u7b49\uff09\u521b\u5efa\u4e00\u4e2a\u5b89\u88c5\u5305\u3002\u5b89\u88c5\u7a0b\u5e8f\u53ef\u4ee5\u81ea\u52a8\u5c06exe\u6587\u4ef6\u548c\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\u590d\u5236\u5230\u76ee\u6807\u8ba1\u7b97\u673a\uff0c\u5e76\u521b\u5efa\u684c\u9762\u5feb\u6377\u65b9\u5f0f\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5206\u53d1\u7a0b\u5e8f\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5206\u53d1\u4f60\u7684\u7a0b\u5e8f\uff0c\u4f8b\u5982\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u3001\u4e91\u5b58\u50a8\uff08\u5982Google Drive\u3001Dropbox\u7b49\uff09\u3001\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982GitHub\u3001GitLab\u7b49\uff09\u6216\u8f6f\u4ef6\u5206\u53d1\u5e73\u53f0\uff08\u5982PyPI\u3001App Store\u7b49\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u5e38\u89c1\u7684\u9519\u8bef\u548c\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<p><p>\u5728\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u53ca\u5176\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f9d\u8d56\u5305\u7f3a\u5931\u9519\u8bef<\/strong>\uff1a\u5982\u679c\u5728\u8fd0\u884cexe\u6587\u4ef6\u65f6\u51fa\u73b0\u4f9d\u8d56\u5305\u7f3a\u5931\u7684\u9519\u8bef\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--hidden-import<\/code>\u9009\u9879\u624b\u52a8\u6307\u5b9a\u7f3a\u5931\u7684\u5305\uff0c\u6216\u8005\u5728.spec\u6587\u4ef6\u4e2d\u624b\u52a8\u6dfb\u52a0\u8fd9\u4e9b\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u9519\u8bef<\/strong>\uff1a\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u4f60\u7684\u811a\u672c\u4e2d\u4f7f\u7528\u4e86\u76f8\u5bf9\u8def\u5f84\uff0c\u53ef\u80fd\u4f1a\u5728\u6253\u5305\u540e\u51fa\u73b0\u8def\u5f84\u9519\u8bef\u3002\u5efa\u8bae\u5728\u811a\u672c\u4e2d\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\uff0c\u6216\u8005\u5728.spec\u6587\u4ef6\u4e2d\u624b\u52a8\u6307\u5b9a\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5728\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u5bfc\u81f4exe\u6587\u4ef6\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u6253\u5305\u547d\u4ee4\uff0c\u6216\u8005\u624b\u52a8\u8c03\u6574\u6587\u4ef6\u6743\u9650\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5305\u540e\u6587\u4ef6\u8fc7\u5927<\/strong>\uff1a\u5982\u679c\u751f\u6210\u7684exe\u6587\u4ef6\u8fc7\u5927\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528<code>--exclude-module<\/code>\u9009\u9879\u6392\u9664\u4e0d\u5fc5\u8981\u7684\u6a21\u5757\uff0c\u6216\u8005\u4f7f\u7528\u538b\u7f29\u5de5\u5177\uff08\u5982UPX\uff09\u5bf9exe\u6587\u4ef6\u8fdb\u884c\u538b\u7f29\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516b\u3001\u4f18\u5316\u6253\u5305\u8fc7\u7a0b<\/p>\n<\/p>\n<p><p>\u5728\u5c06Python\u6587\u4ef6\u8f6c\u6362\u4e3aexe\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u91c7\u53d6\u4e00\u4e9b\u63aa\u65bd\u6765\u4f18\u5316\u6253\u5305\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u6253\u5305\u6548\u7387\u548c\u751f\u6210\u6587\u4ef6\u7684\u6027\u80fd\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u8fdb\u884c\u6253\u5305\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5305\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u9879\u76ee\u7684\u4f9d\u8d56\u5305\u51b2\u7a81\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>virtualenv<\/code>\u6216<code>venv<\/code>\u5de5\u5177\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u5e76\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7cbe\u7b80\u4f9d\u8d56\u5305<\/strong>\uff1a\u5728\u6253\u5305\u4e4b\u524d\uff0c\u68c0\u67e5\u5e76\u79fb\u9664\u4e0d\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\uff0c\u51cf\u5c11\u6253\u5305\u6587\u4ef6\u7684\u4f53\u79ef\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip freeze<\/code>\u547d\u4ee4\u751f\u6210\u4f9d\u8d56\u5305\u5217\u8868\uff0c\u5e76\u624b\u52a8\u7f16\u8f91\u8be5\u5217\u8868\uff0c\u79fb\u9664\u4e0d\u5fc5\u8981\u7684\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316\u4ee3\u7801<\/strong>\uff1a\u5728\u6253\u5305\u4e4b\u524d\uff0c\u4f18\u5316\u4f60\u7684Python\u4ee3\u7801\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u548c\u8d44\u6e90\u6d88\u8017\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u5927\u91cf\u7684\u6570\u636e\u6216\u6267\u884c\u590d\u6742\u7684\u8ba1\u7b97\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u6280\u672f\uff0c\u5145\u5206\u5229\u7528\u591a\u6838\u5904\u7406\u5668\u7684\u6027\u80fd\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u548c\u5efa\u8bae\uff0c\u4f60\u53ef\u4ee5\u5c06Python\u6587\u4ef6\u6210\u529f\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6d4b\u8bd5\u548c\u5206\u53d1\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u4f60\u5728Python\u9879\u76ee\u4e2d\u53d6\u5f97\u6210\u529f\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5c06Python\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u6216cx_Freeze\u3002\u8fd9\u4e9b\u5de5\u5177\u80fd\u591f\u5c06Python\u811a\u672c\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65b9\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002\u4f7f\u7528PyInstaller\u65f6\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pyinstaller your_script.py<\/code>\uff0c\u5b83\u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u7684dist\u6587\u4ef6\u5939\u3002<\/p>\n<p><strong>\u4f7f\u7528PyInstaller\u65f6\uff0c\u662f\u5426\u9700\u8981\u5b89\u88c5\u989d\u5916\u7684\u4f9d\u8d56\uff1f<\/strong><br \/>\u5728\u4f7f\u7528PyInstaller\u4e4b\u524d\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Python\u53ca\u76f8\u5173\u5e93\u3002PyInstaller\u672c\u8eab\u4e5f\u9700\u8981\u901a\u8fc7pip\u5b89\u88c5\u3002\u6b64\u5916\uff0c\u67d0\u4e9b\u590d\u6742\u7684\u5e93\uff08\u5982Pandas\u6216NumPy\uff09\u53ef\u80fd\u9700\u8981\u5728\u6253\u5305\u65f6\u8fdb\u884c\u989d\u5916\u7684\u914d\u7f6e\uff0c\u4ee5\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u90fd\u88ab\u6b63\u786e\u5305\u542b\u3002<\/p>\n<p><strong>\u8f6c\u6362\u540e\u751f\u6210\u7684exe\u6587\u4ef6\u662f\u5426\u53ef\u4ee5\u5728\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff1f<\/strong><br \/>\u751f\u6210\u7684exe\u6587\u4ef6\u53ea\u80fd\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002\u5982\u679c\u9700\u8981\u5728\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\uff08\u5982macOS\u6216Linux\uff09\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\uff0c\u5219\u9700\u5728\u76f8\u5e94\u7684\u73af\u5883\u4e2d\u4f7f\u7528\u76f8\u540c\u7684\u6253\u5305\u5de5\u5177\u8fdb\u884c\u6253\u5305\u3002\u6bcf\u79cd\u64cd\u4f5c\u7cfb\u7edf\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f\u4e0d\u540c\uff0c\u56e0\u6b64\u4e0d\u80fd\u76f4\u63a5\u5728Windows\u4e0a\u8fd0\u884cLinux\u6216macOS\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u628aPython\u6587\u4ef6\u8f6c\u5316\u4e3aexe\u6587\u4ef6 \u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u3001cx_Freeze\u3001Py2exe\u3001p [&hellip;]","protected":false},"author":3,"featured_media":1095481,"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\/1095452"}],"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=1095452"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095452\/revisions"}],"predecessor-version":[{"id":1095485,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095452\/revisions\/1095485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1095481"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1095452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1095452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1095452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}