{"id":1004888,"date":"2024-12-27T10:30:35","date_gmt":"2024-12-27T02:30:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1004888.html"},"modified":"2024-12-27T10:30:40","modified_gmt":"2024-12-27T02:30:40","slug":"%e5%a6%82%e4%bd%95%e6%8a%8apython%e4%bb%a3%e7%a0%81%e5%af%bc%e5%87%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1004888.html","title":{"rendered":"\u5982\u4f55\u628apython\u4ee3\u7801\u5bfc\u51fa"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081638\/b9a2eaa9-ec96-4f06-aa90-71cee4b6b075.webp\" alt=\"\u5982\u4f55\u628apython\u4ee3\u7801\u5bfc\u51fa\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d:<br \/><strong>\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u811a\u672c\u6587\u4ef6\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u6a21\u5757\u3001\u4f7f\u7528Jupyter Notebook\u5bfc\u51fa\u4ee3\u7801<\/strong>\u3002Python\u662f\u4e00\u79cd\u7075\u6d3b\u4e14\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5bfc\u51faPython\u4ee3\u7801\u662f\u8ba9\u5176\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u8fd0\u884c\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6700\u5e38\u89c1\u7684\u5bfc\u51fa\u65b9\u5f0f\u662f\u5c06Python\u4ee3\u7801\u4fdd\u5b58\u4e3a.py\u811a\u672c\u6587\u4ef6\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u800c\u76f4\u63a5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u5f00\u53d1\u573a\u666f\u3002\u5bf9\u4e8e\u9700\u8981\u5728\u6ca1\u6709Python\u89e3\u91ca\u5668\u7684\u73af\u5883\u4e2d\u8fd0\u884c\u4ee3\u7801\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5c06Python\u4ee3\u7801\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e3a\u4e86\u5728\u5176\u4ed6\u9879\u76ee\u4e2d\u91cd\u7528\u4ee3\u7801\uff0c\u53ef\u4ee5\u5c06\u5176\u5bfc\u51fa\u4e3a\u6a21\u5757\u3002\u6b64\u5916\uff0c\u4f7f\u7528Jupyter Notebook\u7684\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u4ee3\u7801\u548c\u6587\u6863\u5bfc\u51fa\u4e3a\u591a\u79cd\u683c\u5f0f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u811a\u672c\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5c06Python\u4ee3\u7801\u4fdd\u5b58\u4e3a\u811a\u672c\u6587\u4ef6\u662f\u6700\u57fa\u672c\u7684\u5bfc\u51fa\u65b9\u5f0f\u3002Python\u811a\u672c\u6587\u4ef6\u4ee5.py\u4e3a\u6269\u5c55\u540d\uff0c\u5305\u542b\u4e86Python\u4ee3\u7801\u3002\u8981\u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Sublime Text\u3001Visual Studio Code\u6216PyCharm\u7b49\u7f16\u8f91\u5668\u7f16\u5199\u4ee3\u7801\u540e\uff0c\u9009\u62e9\u201c\u53e6\u5b58\u4e3a\u201d\u5e76\u6307\u5b9a\u6587\u4ef6\u540d\u548c.py\u6269\u5c55\u540d\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><p>\u4fdd\u5b58\u4e3a.py\u6587\u4ef6\u7684\u597d\u5904\u662f\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8fd0\u884c\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3aexample.py\u7684\u6587\u4ef6\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python example.py<\/code>\u5373\u53ef\u6267\u884c\u5176\u4e2d\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5728\u6ca1\u6709Python\u89e3\u91ca\u5668\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u8fd9\u65f6\uff0c\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08\u5982.exe\u6587\u4ef6\uff09\u3002\u5e38\u7528\u7684\u5de5\u5177\u6709PyInstaller\u3001cx_Freeze\u548cPy2exe\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyInstaller<\/strong><br \/>PyInstaller\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u652f\u6301Windows\u3001MacOS\u548cLinux\u3002\u4f7f\u7528PyInstaller\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pyinstaller your_script.py<\/code>\u5373\u53ef\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002PyInstaller\u4f1a\u81ea\u52a8\u68c0\u6d4b\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u9879\uff0c\u5e76\u5c06\u5176\u6253\u5305\u5728\u4e00\u8d77\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cx_Freeze<\/strong><br \/>cx_Freeze\u662f\u53e6\u4e00\u4e2a\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u652f\u6301\u591a\u4e2a\u5e73\u53f0\u3002\u5b89\u88c5cx_Freeze\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00\u4e2asetup\u811a\u672c\u6765\u914d\u7f6e\u6253\u5305\u8fc7\u7a0b\uff0c\u7136\u540e\u4f7f\u7528\u547d\u4ee4<code>python setup.py build<\/code>\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u6a21\u5757<\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u91cd\u7528\u67d0\u6bb5\u4ee3\u7801\u3002\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u6a21\u5757\uff0c\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u8f7b\u677e\u5bfc\u5165\u548c\u4f7f\u7528\u3002\u8981\u521b\u5efa\u4e00\u4e2a\u6a21\u5757\uff0c\u53ea\u9700\u5c06\u4ee3\u7801\u4fdd\u5b58\u4e3a.py\u6587\u4ef6\uff0c\u7136\u540e\u5728\u5176\u4ed6Python\u6587\u4ef6\u4e2d\u4f7f\u7528<code>import module_name<\/code>\u8bed\u53e5\u5373\u53ef\u5f15\u7528\u3002<\/p>\n<\/p>\n<p><p>\u6a21\u5757\u5316\u4ee3\u7801\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u91cd\u7528\u6027\uff0c\u8fd8\u4f7f\u4ee3\u7801\u66f4\u5bb9\u6613\u7ef4\u62a4\u548c\u7ec4\u7ec7\u3002Python\u6807\u51c6\u5e93\u672c\u8eab\u5c31\u662f\u4e00\u7ec4\u6a21\u5757\uff0c\u63d0\u4f9b\u4e86\u5e7f\u6cdb\u7684\u529f\u80fd\u548c\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Jupyter Notebook\u5bfc\u51fa\u4ee3\u7801<\/p>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u7684\u8ba1\u7b97\u73af\u5883\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3002\u5b83\u5141\u8bb8\u7528\u6237\u5728\u4e00\u4e2a\u6587\u6863\u4e2d\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801\u3001\u8bb0\u5f55\u7b14\u8bb0\u548c\u53ef\u89c6\u5316\u6570\u636e\u3002Jupyter Notebook\u652f\u6301\u591a\u79cd\u5bfc\u51fa\u683c\u5f0f\uff0c\u5305\u62ecHTML\u3001PDF\u3001Markdown\u548cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5bfc\u51faJupyter Notebook\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u5bfc\u51fa\u529f\u80fd\u3002\u5728Notebook\u754c\u9762\u4e2d\uff0c\u9009\u62e9\u201cFile\u201d &gt; \u201cDownload as\u201d\uff0c\u7136\u540e\u9009\u62e9\u6240\u9700\u7684\u5bfc\u51fa\u683c\u5f0f\u3002\u5bfc\u51fa\u7684Python\u811a\u672c\u53ef\u4ee5\u5728\u5176\u4ed6\u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u800cHTML\u683c\u5f0f\u9002\u5408\u7528\u4e8e\u5206\u4eab\u548c\u5c55\u793a\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5bfc\u51fa\u65f6\u7684\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u5bfc\u51faPython\u4ee3\u7801\u65f6\uff0c\u6709\u51e0\u4e2a\u6ce8\u610f\u4e8b\u9879\u9700\u8981\u8003\u8651\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f9d\u8d56\u7ba1\u7406<\/strong><br \/>\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u90fd\u5df2\u5b89\u88c5\u4e14\u7248\u672c\u517c\u5bb9\u3002\u4f7f\u7528\u865a\u62df\u73af\u5883\u6216requirements.txt\u6587\u4ef6\u7ba1\u7406\u4f9d\u8d56\u9879\u662f\u4e2a\u597d\u4e60\u60ef\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u7ba1\u7406<\/strong><br \/>\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\u6587\u4ef6\u8def\u5f84\u5e94\u5c3d\u91cf\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\uff0c\u4ee5\u4fbf\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u8fd0\u884c\u65f6\u4e0d\u51fa\u73b0\u8def\u5f84\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u73af\u5883\u914d\u7f6e<\/strong><br \/>\u5982\u679c\u4ee3\u7801\u4f9d\u8d56\u4e8e\u7279\u5b9a\u7684\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fdd\u5728\u76ee\u6807\u73af\u5883\u4e2d\u6b63\u786e\u8bbe\u7f6e\u8fd9\u4e9b\u53d8\u91cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u6027<\/strong><br \/>\u5982\u679c\u4ee3\u7801\u4e2d\u5305\u542b\u654f\u611f\u4fe1\u606f\uff08\u5982API\u5bc6\u94a5\u6216\u5bc6\u7801\uff09\uff0c\u5e94\u5728\u5bfc\u51fa\u524d\u5c06\u5176\u79fb\u9664\u6216\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u5b58\u50a8\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\u548c\u6ce8\u610f\u4e8b\u9879\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u5e76\u5728\u591a\u79cd\u73af\u5883\u4e2d\u8fd0\u884c\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5bfc\u51fa\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u60a8\u7684Python\u9879\u76ee\u66f4\u5177\u7075\u6d3b\u6027\u548c\u53ef\u79fb\u690d\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u4ee3\u7801\u4fdd\u5b58\u4e3a\u4e0d\u540c\u683c\u5f0f\u7684\u6587\u4ef6\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5c06Python\u4ee3\u7801\u4fdd\u5b58\u4e3a\u4e0d\u540c\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u4f8b\u5982\u6587\u672c\u6587\u4ef6\uff08.txt\uff09\u3001\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u6216Jupyter Notebook\uff08.ipynb\uff09\u3002\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982Notepad\u6216VS Code\uff09\u76f4\u63a5\u5c06\u4ee3\u7801\u7c98\u8d34\u5e76\u4fdd\u5b58\u4e3a.txt\u6587\u4ef6\uff0c\u6216\u5728Jupyter Notebook\u4e2d\u9009\u62e9\u201c\u6587\u4ef6\u201d&gt;\u201c\u4e0b\u8f7d\u4e3a\u201d\u9009\u9879\u6765\u5bfc\u51fa\u4e3a\u591a\u79cd\u683c\u5f0f\u3002<\/p>\n<p><strong>\u5728\u5bfc\u51faPython\u4ee3\u7801\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u9700\u8981\u907f\u514d\uff1f<\/strong><br \/>\u5728\u5bfc\u51fa\u4ee3\u7801\u65f6\uff0c\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u6587\u4ef6\u8def\u5f84\u4e0d\u6b63\u786e\u3001\u7f3a\u5c11\u5fc5\u8981\u7684\u5e93\u6216\u6a21\u5757\u3001\u4ee5\u53ca\u672a\u5904\u7406\u7684\u8bed\u6cd5\u9519\u8bef\u3002\u786e\u4fdd\u5728\u5bfc\u51fa\u524d\u8fdb\u884c\u4ee3\u7801\u8c03\u8bd5\uff0c\u5e76\u68c0\u67e5\u6587\u4ef6\u540d\u548c\u6269\u5c55\u540d\u7684\u6b63\u786e\u6027\uff0c\u4ee5\u514d\u9020\u6210\u540e\u7eed\u4f7f\u7528\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u5230GitHub\u6216\u5176\u4ed6\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff1f<\/strong><br \/>\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u5230GitHub\u7b49\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u9996\u5148\u9700\u8981\u5728\u672c\u5730\u521b\u5efa\u4e00\u4e2aGit\u4ed3\u5e93\u3002\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u8f93\u5165<code>git init<\/code>\u6765\u521d\u59cb\u5316\u4ed3\u5e93\uff0c\u7136\u540e\u5c06\u4ee3\u7801\u6dfb\u52a0\u5230\u7248\u672c\u63a7\u5236\u4e2d\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u901a\u8fc7<code>git commit -m &quot;Your message&quot;<\/code>\u63d0\u4ea4\u66f4\u6539\uff0c\u5e76\u4f7f\u7528<code>git push<\/code>\u5c06\u4ee3\u7801\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u786e\u4fdd\u5728\u63a8\u9001\u4e4b\u524d\u8bbe\u7f6e\u597d\u8fdc\u7a0b\u4ed3\u5e93\u7684\u94fe\u63a5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d:\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u811a\u672c\u6587\u4ef6\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u6a21\u5757\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1004899,"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\/1004888"}],"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=1004888"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004888\/revisions"}],"predecessor-version":[{"id":1004902,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004888\/revisions\/1004902"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1004899"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1004888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1004888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1004888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}