{"id":1018803,"date":"2024-12-27T12:46:20","date_gmt":"2024-12-27T04:46:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1018803.html"},"modified":"2024-12-27T12:46:28","modified_gmt":"2024-12-27T04:46:28","slug":"python%e5%ae%89%e8%a3%85%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1018803.html","title":{"rendered":"python\u5b89\u88c5\u5982\u4f55\u8fd0\u884c\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25161421\/5b2f32b7-e71e-4cda-8b6b-0c6b62f12204.webp\" alt=\"python\u5b89\u88c5\u5982\u4f55\u8fd0\u884c\u73af\u5883\" \/><\/p>\n<p><p> \u5728Python\u7684\u5b89\u88c5\u548c\u8fd0\u884c\u73af\u5883\u8bbe\u7f6e\u8fc7\u7a0b\u4e2d\uff0c<strong>\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u7ba1\u7406Python\u5305<\/strong>\u662f\u81f3\u5173\u91cd\u8981\u7684\u6b65\u9aa4\u3002<strong>\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c<\/strong>\u975e\u5e38\u5173\u952e\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7248\u672c\u7684Python\u3002\u4e3a\u4e86\u786e\u4fdd\u9879\u76ee\u7684\u517c\u5bb9\u6027\u548c\u7a33\u5b9a\u6027\uff0c\u5728\u9879\u76ee\u5f00\u59cb\u65f6\u9009\u62e9\u548c\u9501\u5b9a\u4e00\u4e2aPython\u7248\u672c\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002\u5b89\u88c5Python\u89e3\u91ca\u5668\u540e\uff0c\u5fc5\u987b\u5c06\u5176\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u8f7b\u677e\u4f7f\u7528Python\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u662f\u5f00\u59cb\u4efb\u4f55Python\u9879\u76ee\u7684\u7b2c\u4e00\u6b65\u3002Python\u6709\u591a\u4e2a\u7248\u672c\uff0c\u4e3b\u8981\u5206\u4e3aPython 2.x\u548cPython 3.x\u7cfb\u5217\u3002Python 2.x\u867d\u7136\u5728\u5f88\u591a\u65e7\u9879\u76ee\u4e2d\u4ecd\u7136\u4f7f\u7528\uff0c\u4f46\u5b98\u65b9\u5df2\u4e8e2020\u5e74\u505c\u6b62\u652f\u6301\u3002\u56e0\u6b64\uff0c\u5bf9\u4e8e\u65b0\u9879\u76ee\uff0c\u63a8\u8350\u4f7f\u7528Python 3.x\u7cfb\u5217\u3002\u9009\u62e9\u6b63\u786e\u7684\u7248\u672c\u53d6\u51b3\u4e8e\u9879\u76ee\u7684\u9700\u6c42\u548c\u4f9d\u8d56\u5e93\u7684\u517c\u5bb9\u6027\u3002<\/p>\n<\/p>\n<p><p>Python 3.x\u7248\u672c\u4e0d\u65ad\u66f4\u65b0\uff0c\u901a\u5e38\u5efa\u8bae\u4f7f\u7528\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\uff0c\u56e0\u4e3a\u5b83\u4eec\u5305\u542b\u4e86\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\u3002\u4e3a\u4e86\u786e\u4fdd\u9879\u76ee\u7684\u517c\u5bb9\u6027\uff0c\u53ef\u4ee5\u5728\u9879\u76ee\u5f00\u59cb\u65f6\u9501\u5b9a\u4e00\u4e2a\u7279\u5b9a\u7684Python\u7248\u672c\uff0c\u5e76\u5728\u9879\u76ee\u751f\u547d\u5468\u671f\u5185\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>Python\u89e3\u91ca\u5668\u662f\u8fd0\u884cPython\u4ee3\u7801\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u90fd\u63d0\u4f9b\u4e86Python\u5b89\u88c5\u5305\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6765\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u901a\u8fc7\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305<\/strong>\uff1a\u5728Python\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u9002\u5408\u81ea\u5df1\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u7248\u672c\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u88c5\u5305\uff0c\u6309\u7167\u63d0\u793a\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5668<\/strong>\uff1a\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5982apt\u6216yum\u6765\u5b89\u88c5Python\u3002\u5bf9\u4e8emacOS\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528Homebrew\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Anaconda<\/strong>\uff1aAnaconda\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684Python\u53d1\u884c\u7248\uff0c\u5305\u542b\u4e86\u5927\u91cf\u7684Python\u5e93\u548c\u5de5\u5177\uff0c\u9002\u5408\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u7814\u7a76\u4eba\u5458\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u786e\u4fdd\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u4ee5\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u5b89\u88c5Python\u540e\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528Python\u547d\u4ee4\u3002\u4ee5\u4e0b\u662f\u914d\u7f6e\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6253\u5f00\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\uff0c\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\uff0c\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e2d\u627e\u5230\u5e76\u7f16\u8f91\u201cPath\u201d\u53d8\u91cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5c06Python\u5b89\u88c5\u76ee\u5f55\u548cScripts\u76ee\u5f55\u6dfb\u52a0\u5230Path\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4efb\u4f55\u76ee\u5f55\u4e0b\u76f4\u63a5\u4f7f\u7528<code>python<\/code>\u6216<code>python3<\/code>\u547d\u4ee4\u6765\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684IDE\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6d41\u884c\u7684Python IDE\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong>\uff1a\u7531JetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u5f00\u53d1\uff0c\u652f\u6301\u667a\u80fd\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u6d4b\u8bd5\u548c\u7248\u672c\u63a7\u5236\uff0c\u9002\u5408\u5927\u578b\u9879\u76ee\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong>\uff1a\u514d\u8d39\u3001\u5f00\u6e90\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u63d2\u4ef6\u751f\u6001\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5Python\u6269\u5c55\u6765\u652f\u6301Python\u5f00\u53d1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong>\uff1a\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9879\u76ee\uff0c\u652f\u6301\u4ea4\u4e92\u5f0f\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Spyder<\/strong>\uff1a\u96c6\u6210\u4e86\u8bb8\u591a\u79d1\u5b66\u8ba1\u7b97\u5de5\u5177\uff0c\u9002\u5408\u6570\u636e\u5206\u6790\u548c\u7814\u7a76\u4eba\u5458\u4f7f\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u9009\u62e9IDE\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u7684\u89c4\u6a21\u3001\u4e2a\u4eba\u7684\u4f7f\u7528\u4e60\u60ef\u548c\u7279\u5b9a\u7684\u529f\u80fd\u9700\u6c42\u6765\u51b3\u5b9a\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7ba1\u7406Python\u5305<\/h3>\n<\/p>\n<p><p>Python\u6709\u4e00\u4e2a\u5f3a\u5927\u7684\u5305\u7ba1\u7406\u5de5\u5177\u2014\u2014pip\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528pip\u7684\u4e00\u4e9b\u57fa\u672c\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5305<\/strong>\uff1a<code>pip install package_name<\/code><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u5305<\/strong>\uff1a<code>pip install --upgrade package_name<\/code><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5378\u8f7d\u5305<\/strong>\uff1a<code>pip uninstall package_name<\/code><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u5305<\/strong>\uff1a<code>pip list<\/code><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e3a\u4e86\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u3002\u901a\u8fc7<code>pip freeze &gt; requirements.txt<\/code>\u53ef\u4ee5\u5c06\u5f53\u524d\u73af\u5883\u7684\u6240\u6709\u4f9d\u8d56\u5bfc\u51fa\uff0c\u7136\u540e\u5728\u5176\u4ed6\u73af\u5883\u4e2d\u901a\u8fc7<code>pip install -r requirements.txt<\/code>\u6765\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982venv\u6216virtualenv\uff09\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u9879\u76ee\u5f00\u53d1\u4e2d\u7684\u91cd\u8981\u5de5\u5177\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4e3a\u4e0d\u540c\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u4e0d\u4f1a\u53d1\u751f\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528Python\u81ea\u5e26\u7684<code>venv<\/code>\u6a21\u5757\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c<code>python -m venv env_name<\/code>\uff0c\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>env_name<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728Windows\u4e0b\uff0c\u901a\u8fc7<code>.\\env_name\\Scripts\\activate<\/code>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u5728macOS\u6216Linux\u7cfb\u7edf\u4e0b\uff0c\u901a\u8fc7<code>source env_name\/bin\/activate<\/code>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u865a\u62df\u73af\u5883\u4e2d\u7684\u5305<\/strong>\uff1a\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f7f\u7528pip\u7ba1\u7406\u5305\u5c06\u53ea\u4f1a\u5f71\u54cd\u5f53\u524d\u73af\u5883\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>deactivate<\/code>\u53ef\u4ee5\u9000\u51fa\u5f53\u524d\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u4f9d\u8d56\u72ec\u7acb\u6027\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u914d\u7f6e\u7248\u672c\u63a7\u5236<\/h3>\n<\/p>\n<p><p>\u7248\u672c\u63a7\u5236\u662f\u9879\u76ee\u5f00\u53d1\u4e2d\u7684\u5173\u952e\u90e8\u5206\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u8ddf\u8e2a\u4ee3\u7801\u53d8\u66f4\u3001\u534f\u4f5c\u5f00\u53d1\u4ee5\u53ca\u7ba1\u7406\u9879\u76ee\u7684\u4e0d\u540c\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u7248\u672c\u63a7\u5236\u7cfb\u7edf<\/strong>\uff1aGit\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u652f\u6301\u5206\u5e03\u5f0f\u5f00\u53d1\u548c\u5f3a\u5927\u7684\u5206\u652f\u7ba1\u7406\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521d\u59cb\u5316Git\u4ed3\u5e93<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c<code>git init<\/code>\u521d\u59cb\u5316Git\u4ed3\u5e93\u3002\u901a\u8fc7<code>git add .<\/code>\u548c<code>git commit -m &quot;Initial commit&quot;<\/code>\u63d0\u4ea4\u521d\u59cb\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Git\u5206\u652f<\/strong>\uff1a\u5206\u652f\u662fGit\u7684\u5f3a\u5927\u529f\u80fd\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u5728\u4e0d\u540c\u7684\u5206\u652f\u4e0a\u8fdb\u884c\u72ec\u7acb\u7684\u5f00\u53d1\u3002\u4f7f\u7528<code>git branch branch_name<\/code>\u521b\u5efa\u65b0\u5206\u652f\uff0c<code>git checkout branch_name<\/code>\u5207\u6362\u5206\u652f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fdc\u7a0b\u4ed3\u5e93<\/strong>\uff1aGit\u652f\u6301\u5c06\u4ee3\u7801\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u5982GitHub\u3001GitLab\u548cBitbucket\u3002\u901a\u8fc7<code>git remote add origin repository_url<\/code>\u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u5e76\u4f7f\u7528<code>git push origin branch_name<\/code>\u63a8\u9001\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u7248\u672c\u63a7\u5236\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u7ba1\u7406\u9879\u76ee\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u5e76\u4e0e\u56e2\u961f\u6210\u5458\u534f\u4f5c\u5f00\u53d1\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u8c03\u8bd5\u548c\u6d4b\u8bd5<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u548c\u6d4b\u8bd5\u662f\u8f6f\u4ef6\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u90e8\u5206\u3002Python\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u8c03\u8bd5\u548c\u6d4b\u8bd5\u5de5\u5177\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9a\u4f4d\u548c\u4fee\u590d\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8c03\u8bd5\u5de5\u5177<\/strong>\uff1aPython\u5185\u7f6e\u7684<code>pdb<\/code>\u6a21\u5757\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3001\u68c0\u67e5\u53d8\u91cf\u503c\u548c\u8bbe\u7f6e\u65ad\u70b9\u3002\u5927\u591a\u6570IDE\u4e5f\u63d0\u4f9b\u4e86\u56fe\u5f62\u5316\u8c03\u8bd5\u5de5\u5177\uff0c\u652f\u6301\u65ad\u70b9\u8c03\u8bd5\u548c\u53d8\u91cf\u76d1\u63a7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5355\u5143\u6d4b\u8bd5<\/strong>\uff1aPython\u7684<code>unittest<\/code>\u6a21\u5757\u662f\u4e00\u4e2a\u5185\u7f6e\u7684\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\uff0c\u652f\u6301\u81ea\u52a8\u5316\u6d4b\u8bd5\u548c\u6d4b\u8bd5\u7528\u4f8b\u7ec4\u7ec7\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5\u8986\u76d6\u7387<\/strong>\uff1a<code>coverage<\/code>\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u68c0\u67e5\u6d4b\u8bd5\u8986\u76d6\u7387\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6bcf\u4e00\u884c\u90fd\u7ecf\u8fc7\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6301\u7eed\u96c6\u6210<\/strong>\uff1a\u6301\u7eed\u96c6\u6210\u5de5\u5177\uff08\u5982Jenkins\u3001Travis CI\uff09\u53ef\u4ee5\u81ea\u52a8\u5316\u6d4b\u8bd5\u6d41\u7a0b\uff0c\u5728\u4ee3\u7801\u63d0\u4ea4\u540e\u81ea\u52a8\u8fd0\u884c\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u8c03\u8bd5\u548c\u6d4b\u8bd5\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u90e8\u7f72\u548c\u53d1\u5e03<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u5f00\u53d1\u548c\u6d4b\u8bd5\u540e\uff0c\u9879\u76ee\u9700\u8981\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u4e2d\u3002Python\u6709\u591a\u79cd\u90e8\u7f72\u548c\u53d1\u5e03\u65b9\u5f0f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6848\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Web\u5e94\u7528\u90e8\u7f72<\/strong>\uff1a\u5bf9\u4e8eWeb\u5e94\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528WSGI\u670d\u52a1\u5668\uff08\u5982Gunicorn\u3001uWSGI\uff09\u548cWeb\u6846\u67b6\uff08\u5982Django\u3001Flask\uff09\u8fdb\u884c\u90e8\u7f72\u3002\u53ef\u4ee5\u9009\u62e9\u4f20\u7edf\u7684\u670d\u52a1\u5668\u90e8\u7f72\u65b9\u5f0f\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e91\u670d\u52a1\uff08\u5982AWS\u3001Heroku\uff09\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5305\u548c\u53d1\u5e03<\/strong>\uff1aPython\u9879\u76ee\u53ef\u4ee5\u4f7f\u7528<code>setuptools<\/code>\u548c<code>wheel<\/code>\u6253\u5305\uff0c\u5e76\u901a\u8fc7PyPI\u53d1\u5e03\u3002\u901a\u8fc7<code>python setup.py sdist bdist_wheel<\/code>\u53ef\u4ee5\u751f\u6210\u9879\u76ee\u7684\u5206\u53d1\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Docker\u5316<\/strong>\uff1aDocker\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u5bb9\u5668\u5316\u6280\u672f\uff0c\u53ef\u4ee5\u5c06\u5e94\u7528\u53ca\u5176\u4f9d\u8d56\u6253\u5305\u6210\u4e00\u4e2a\u955c\u50cf\uff0c\u786e\u4fdd\u5728\u4efb\u4f55\u73af\u5883\u4e0b\u90fd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u901a\u8fc7\u7f16\u5199Dockerfile\uff0c\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u9879\u76ee\u7684Docker\u955c\u50cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u90e8\u7f72<\/strong>\uff1a\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\u5de5\u5177\uff08\u5982GitLab CI\u3001CircleCI\uff09\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u90e8\u7f72\u3002\u5728\u4ee3\u7801\u63d0\u4ea4\u540e\uff0c\u81ea\u52a8\u6784\u5efa\u548c\u90e8\u7f72\u9879\u76ee\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5408\u7406\u7684\u90e8\u7f72\u548c\u53d1\u5e03\u7b56\u7565\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u7a33\u5b9a\u8fd0\u884c\uff0c\u5e76\u5feb\u901f\u54cd\u5e94\u7528\u6237\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u4f18\u5316\u548c\u7ef4\u62a4<\/h3>\n<\/p>\n<p><p>\u4f18\u5316\u548c\u7ef4\u62a4\u662f\u8f6f\u4ef6\u751f\u547d\u5468\u671f\u7684\u91cd\u8981\u9636\u6bb5\u3002\u5728\u9879\u76ee\u4e0a\u7ebf\u540e\uff0c\u5f00\u53d1\u8005\u9700\u8981\u6301\u7eed\u5173\u6ce8\u9879\u76ee\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\uff0c\u5e76\u8fdb\u884c\u5fc5\u8981\u7684\u4f18\u5316\u548c\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u901a\u8fc7\u5206\u6790\u4ee3\u7801\u6027\u80fd\uff0c\u627e\u51fa\u74f6\u9888\u5e76\u8fdb\u884c\u4f18\u5316\u3002\u53ef\u4ee5\u4f7f\u7528<code>cProfile<\/code>\u6a21\u5757\u8fdb\u884c\u6027\u80fd\u5206\u6790\uff0c\u627e\u51fa\u8017\u65f6\u8f83\u591a\u7684\u51fd\u6570\uff0c\u5e76\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u5b58\u4f18\u5316<\/strong>\uff1aPython\u7684<code>memory_profiler<\/code>\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5206\u6790\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\u901a\u8fc7\u4f18\u5316\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\uff0c\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u65e5\u5fd7\u548c\u76d1\u63a7<\/strong>\uff1a\u901a\u8fc7\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u5de5\u5177\uff0c\u8ddf\u8e2a\u9879\u76ee\u8fd0\u884c\u72b6\u6001\uff0c\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\u3002Python\u7684<code>logging<\/code>\u6a21\u5757\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u65e5\u5fd7\u5de5\u5177\uff0c\u53ef\u4ee5\u8bb0\u5f55\u4e0d\u540c\u7ea7\u522b\u7684\u65e5\u5fd7\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u6027\u7ef4\u62a4<\/strong>\uff1a\u5b9a\u671f\u68c0\u67e5\u9879\u76ee\u7684\u5b89\u5168\u6027\uff0c\u66f4\u65b0\u4f9d\u8d56\u5e93\uff0c\u4fee\u590d\u5df2\u77e5\u6f0f\u6d1e\u3002\u4f7f\u7528\u5b89\u5168\u5de5\u5177\uff08\u5982Bandit\uff09\u8fdb\u884c\u4ee3\u7801\u626b\u63cf\uff0c\u786e\u4fdd\u4ee3\u7801\u5b89\u5168\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u6301\u7eed\u7684\u4f18\u5316\u548c\u7ef4\u62a4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u63d0\u9ad8\u9879\u76ee\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\uff0c\u5ef6\u957f\u9879\u76ee\u7684\u751f\u547d\u5468\u671f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5b89\u88c5Python\u7684\u6b65\u9aa4\u56e0\u64cd\u4f5c\u7cfb\u7edf\u800c\u5f02\u3002\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u53ef\u4ee5\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408\u7684\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6309\u7167\u5b89\u88c5\u5411\u5bfc\u5b8c\u6210\u5b89\u88c5\u3002macOS\u7528\u6237\u53ef\u4ee5\u901a\u8fc7Homebrew\u6216\u76f4\u63a5\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u6765\u5b89\u88c5\u3002Linux\u7528\u6237\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff0c\u4f8b\u5982\u5728Ubuntu\u4e0a\u4f7f\u7528\u547d\u4ee4<code>sudo apt-get install python3<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u786e\u4fdd\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u52fe\u9009\u6dfb\u52a0Python\u5230\u7cfb\u7edf\u8def\u5f84\u7684\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u3002<\/p>\n<p><strong>Python\u73af\u5883\u7684\u914d\u7f6e\u6709\u54ea\u4e9b\u63a8\u8350\u7684\u5de5\u5177\uff1f<\/strong><br \/>\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406Python\u73af\u5883\uff0c\u63a8\u8350\u4f7f\u7528\u865a\u62df\u73af\u5883\u5de5\u5177\uff0c\u5982<code>venv<\/code>\u6216<code>virtualenv<\/code>\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u4ee5\u907f\u514d\u5305\u4e4b\u95f4\u7684\u7248\u672c\u51b2\u7a81\u3002\u6b64\u5916\uff0cAnaconda\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u9009\u62e9\uff0c\u7279\u522b\u9002\u5408\u9700\u8981\u5904\u7406\u79d1\u5b66\u8ba1\u7b97\u6216\u6570\u636e\u5206\u6790\u7684\u7528\u6237\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u5305\u7ba1\u7406\u548c\u73af\u5883\u7ba1\u7406\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u5728\u5b89\u88c5Python\u540e\uff0c\u5982\u4f55\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u9a8c\u8bc1Python\u5b89\u88c5\u6210\u529f\u4e0e\u5426\u975e\u5e38\u7b80\u5355\u3002\u7528\u6237\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u5982\u679c\u663e\u793a\u51faPython\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8fd0\u884c\u7b80\u5355\u7684Python\u4ee3\u7801\uff0c\u4f8b\u5982\u8f93\u5165<code>print(&quot;Hello, World!&quot;)<\/code>\uff0c\u5982\u679c\u6ca1\u6709\u9519\u8bef\u63d0\u793a\uff0c\u8bf4\u660e\u8fd0\u884c\u73af\u5883\u6b63\u5e38\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u7684\u5b89\u88c5\u548c\u8fd0\u884c\u73af\u5883\u8bbe\u7f6e\u8fc7\u7a0b\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u9009 [&hellip;]","protected":false},"author":3,"featured_media":1018823,"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\/1018803"}],"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=1018803"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018803\/revisions"}],"predecessor-version":[{"id":1018825,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018803\/revisions\/1018825"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1018823"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1018803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1018803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1018803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}