{"id":1174564,"date":"2025-01-15T17:19:56","date_gmt":"2025-01-15T09:19:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1174564.html"},"modified":"2025-01-15T17:19:58","modified_gmt":"2025-01-15T09:19:58","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%bb%ba%e7%ab%8b%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1174564.html","title":{"rendered":"\u5982\u4f55\u7528python\u5efa\u7acb\u9879\u76ee"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26080026\/8fd98998-cc54-405c-a1e1-ec89e1599fa6.webp\" alt=\"\u5982\u4f55\u7528python\u5efa\u7acb\u9879\u76ee\" \/><\/p>\n<p><p> <strong>\u7528Python\u5efa\u7acb\u9879\u76ee\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u521b\u5efa\u9879\u76ee\u7ed3\u6784\u3001\u521d\u59cb\u5316\u7248\u672c\u63a7\u5236\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u3001\u7f16\u5199\u548c\u6d4b\u8bd5\u4ee3\u7801\u3001\u64b0\u5199\u6587\u6863<\/strong>\u3002\u5176\u4e2d\uff0c\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u662f\u975e\u5e38\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u5b83\u51b3\u5b9a\u4e86\u9879\u76ee\u7684\u6574\u4f53\u67b6\u6784\u548c\u5de5\u5177\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u9879\u76ee\u7c7b\u578b\uff1a\u5728\u5f00\u59cb\u4efb\u4f55\u7f16\u7a0b\u9879\u76ee\u4e4b\u524d\uff0c\u660e\u786e\u9879\u76ee\u7684\u7c7b\u578b\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002Python\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u7c7b\u578b\u7684\u9879\u76ee\uff0c\u5982Web\u5f00\u53d1\u3001\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3001\u81ea\u52a8\u5316\u811a\u672c\u7b49\u3002\u4e0d\u540c\u7c7b\u578b\u7684\u9879\u76ee\u9700\u8981\u4e0d\u540c\u7684\u5e93\u548c\u6846\u67b6\uff0c\u56e0\u6b64\u5728\u5f00\u59cb\u4e4b\u524d\u9700\u8981\u505a\u597d\u89c4\u5212\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u8ba1\u5212\u5f00\u53d1\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u9009\u62e9Django\u6216Flask\u4f5c\u4e3a\u6846\u67b6\u3002\u5982\u679c\u4f60\u8fdb\u884c\u6570\u636e\u5206\u6790\uff0cpandas\u548cNumPy\u53ef\u80fd\u662f\u5fc5\u5907\u7684\u5de5\u5177\u3002\u660e\u786e\u9879\u76ee\u7c7b\u578b\u540e\uff0c\u53ef\u4ee5\u66f4\u6709\u9488\u5bf9\u6027\u5730\u8fdb\u884c\u540e\u7eed\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e00\u3001\u9009\u62e9\u9879\u76ee\u7c7b\u578b<\/strong><\/h2>\n<p><p>\u5728\u5f00\u59cb\u4e00\u4e2aPython\u9879\u76ee\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u660e\u786e\u9879\u76ee\u7684\u7c7b\u578b\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u9879\u76ee\u7c7b\u578b\u5f80\u5f80\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u5de5\u5177\u548c\u5e93\u3002<\/p>\n<\/p>\n<p><h2>1\u3001Web\u5f00\u53d1<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u51b3\u5b9a\u5f00\u53d1\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\uff0cPython\u6709\u51e0\u4e2a\u6d41\u884c\u7684\u6846\u67b6\u53ef\u4ee5\u9009\u62e9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>Django<\/strong>\uff1a\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6784\u5efa\u590d\u6742\u548c\u6570\u636e\u9a71\u52a8\u7684Web\u5e94\u7528\u3002<\/li>\n<li><strong>Flask<\/strong>\uff1a\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6784\u5efa\u5c0f\u578b\u548c\u4e2d\u578bWeb\u5e94\u7528\uff0c\u7075\u6d3b\u6027\u66f4\u9ad8\u3002<\/li>\n<li><strong>FastAPI<\/strong>\uff1a\u4e00\u4e2a\u73b0\u4ee3\u3001\u5feb\u901f\uff08\u9ad8\u6027\u80fd\uff09\u7684Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6784\u5efaAPI\u3002<\/li>\n<\/ul>\n<p><p>\u9009\u62e9Web\u5f00\u53d1\u6846\u67b6\u65f6\uff0c\u9700\u8981\u8003\u8651\u9879\u76ee\u7684\u590d\u6742\u6027\u3001\u56e2\u961f\u7684\u6280\u672f\u6808\u548c\u5f00\u53d1\u7684\u901f\u5ea6\u3002\u4f8b\u5982\uff0cDjango\u6709\u5f88\u591a\u5185\u7f6e\u529f\u80fd\uff0c\u53ef\u4ee5\u52a0\u5feb\u5f00\u53d1\u901f\u5ea6\uff0c\u4f46\u53ef\u80fd\u4f1a\u5f15\u5165\u4e0d\u5fc5\u8981\u7684\u590d\u6742\u6027\u3002Flask\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\uff0c\u4f46\u5f00\u53d1\u8005\u9700\u8981\u81ea\u5df1\u5b9e\u73b0\u66f4\u591a\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u9879\u76ee\u6d89\u53ca\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\uff0cPython\u6709\u4e30\u5bcc\u7684\u5e93\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>Pandas<\/strong>\uff1a\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\u3002<\/li>\n<li><strong>NumPy<\/strong>\uff1a\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u57fa\u7840\u5305\uff0c\u63d0\u4f9b\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u5404\u79cd\u5de5\u5177\u3002<\/li>\n<li><strong>SciPy<\/strong>\uff1a\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u548c\u5de5\u7a0b\u8ba1\u7b97\u7684\u5e93\u3002<\/li>\n<li><strong>Matplotlib<\/strong> \u548c <strong>Seaborn<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u5e93\u3002<\/li>\n<\/ul>\n<p><p>\u9009\u62e9\u6570\u636e\u5206\u6790\u5de5\u5177\u65f6\uff0c\u9700\u8981\u8003\u8651\u6570\u636e\u7684\u89c4\u6a21\u3001\u5206\u6790\u7684\u590d\u6742\u6027\u4ee5\u53ca\u53ef\u89c6\u5316\u7684\u9700\u6c42\u3002\u4f8b\u5982\uff0cPandas\u975e\u5e38\u9002\u5408\u5904\u7406\u7ed3\u6784\u5316\u6570\u636e\uff0c\u800cNumPy\u5219\u66f4\u9002\u5408\u8fdb\u884c\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u673a\u5668\u5b66\u4e60<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u9879\u76ee\u6d89\u53ca\u673a\u5668\u5b66\u4e60\u548c<a href=\"https:\/\/docs.pingcode.com\/tag\/AI\" target=\"_blank\">\u4eba\u5de5\u667a\u80fd<\/a>\uff0cPython\u4e5f\u6709\u5f88\u591a\u6210\u719f\u7684\u5e93\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>scikit-learn<\/strong>\uff1a\u4e00\u4e2a\u7b80\u5355\u9ad8\u6548\u7684\u673a\u5668\u5b66\u4e60\u5e93\uff0c\u9002\u7528\u4e8e\u6570\u636e\u6316\u6398\u548c\u6570\u636e\u5206\u6790\u3002<\/li>\n<li><strong>TensorFlow<\/strong> \u548c <strong>PyTorch<\/strong>\uff1a\u7528\u4e8e\u6784\u5efa\u548c\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7684\u6846\u67b6\u3002<\/li>\n<li><strong>Keras<\/strong>\uff1a\u4e00\u4e2a\u9ad8\u7ea7\u795e\u7ecf\u7f51\u7edcAPI\uff0c\u80fd\u591f\u8fd0\u884c\u5728TensorFlow\u3001Theano\u548cCNTK\u4e4b\u4e0a\u3002<\/li>\n<\/ul>\n<p><p>\u9009\u62e9\u673a\u5668\u5b66\u4e60\u5de5\u5177\u65f6\uff0c\u9700\u8981\u8003\u8651\u6a21\u578b\u7684\u590d\u6742\u6027\u3001\u8bad\u7ec3\u901f\u5ea6\u548c\u90e8\u7f72\u9700\u6c42\u3002\u4f8b\u5982\uff0cscikit-learn\u9002\u5408\u5feb\u901f\u6784\u5efa\u548c\u9a8c\u8bc1\u6a21\u578b\uff0c\u800cTensorFlow\u548cPyTorch\u5219\u9002\u5408\u6784\u5efa\u590d\u6742\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e8c\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<p><p>\u5728\u5f00\u59cb\u4e00\u4e2a\u65b0\u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u9879\u76ee\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u4e3a\u4ec0\u4e48\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u7684\u4e00\u4e2a\u91cd\u8981\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u4f60\u5728\u4e00\u4e2a\u9694\u79bb\u7684\u73af\u5883\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406\u5305\u3002\u8fd9\u5bf9\u4e8e\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u975e\u5e38\u6709\u5e2e\u52a9\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u80fd\u6709\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u4f7f\u7528Django 2.2\uff0c\u800c\u53e6\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u4f7f\u7528Django 3.1\u3002\u5982\u679c\u4e0d\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u5b89\u88c5\u4e00\u4e2a\u7248\u672c\u7684Django\u53ef\u80fd\u4f1a\u7834\u574f\u53e6\u4e00\u4e2a\u9879\u76ee\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u5982\u4f55\u521b\u5efa\u865a\u62df\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u521b\u5efa\u865a\u62df\u73af\u5883\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u7684<code>venv<\/code>\u6a21\u5757\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u5982<code>virtualenv<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>venv<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5b89\u88c5\u865a\u62df\u73af\u5883\u6a21\u5757<\/p>\n<p>pip install venv<\/p>\n<h2><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<p>python -m venv myenv<\/p>\n<h2><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<h2><strong>Windows<\/strong><\/h2>\n<p>myenv\\Scripts\\activate<\/p>\n<h2><strong>macOS\/Linux<\/strong><\/h2>\n<p>source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>virtualenv<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5b89\u88c5virtualenv<\/p>\n<p>pip install virtualenv<\/p>\n<h2><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<p>virtualenv myenv<\/p>\n<h2><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<h2><strong>Windows<\/strong><\/h2>\n<p>myenv\\Scripts\\activate<\/p>\n<h2><strong>macOS\/Linux<\/strong><\/h2>\n<p>source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u5176\u4e2d\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u5305\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5305\u53ea\u4f1a\u5728\u8fd9\u4e2a\u865a\u62df\u73af\u5883\u4e2d\u53ef\u7528\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e09\u3001\u521b\u5efa\u9879\u76ee\u7ed3\u6784<\/strong><\/h2>\n<p><p>\u4e00\u4e2a\u826f\u597d\u7684\u9879\u76ee\u7ed3\u6784\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ec4\u7ec7\u4ee3\u7801\uff0c\u63d0\u9ad8\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u57fa\u672c\u9879\u76ee\u7ed3\u6784<\/h2>\n<\/p>\n<p><p>\u4e00\u4e2a\u5178\u578b\u7684Python\u9879\u76ee\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>my_project\/<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 README.md<\/p>\n<p>\u251c\u2500\u2500 setup.py<\/p>\n<p>\u251c\u2500\u2500 requirements.txt<\/p>\n<p>\u251c\u2500\u2500 .gitignore<\/p>\n<p>\u251c\u2500\u2500 my_project\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 module1.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 module2.py<\/p>\n<p>\u2502   \u2514\u2500\u2500 ...<\/p>\n<p>\u2514\u2500\u2500 tests\/<\/p>\n<p>    \u251c\u2500\u2500 __init__.py<\/p>\n<p>    \u251c\u2500\u2500 test_module1.py<\/p>\n<p>    \u251c\u2500\u2500 test_module2.py<\/p>\n<p>    \u2514\u2500\u2500 ...<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>README.md<\/strong>\uff1a\u9879\u76ee\u7684\u7b80\u4ecb\u548c\u4f7f\u7528\u8bf4\u660e\u3002<\/li>\n<li><strong>setup.py<\/strong>\uff1a\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u9879\u76ee\u4fe1\u606f\u548c\u4f9d\u8d56\u5305\u3002<\/li>\n<li><strong>requirements.txt<\/strong>\uff1a\u5217\u51fa\u9879\u76ee\u7684\u6240\u6709\u4f9d\u8d56\u5305\u3002<\/li>\n<li><strong>.gitignore<\/strong>\uff1a\u5217\u51fa\u4e0d\u9700\u8981\u7eb3\u5165\u7248\u672c\u63a7\u5236\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002<\/li>\n<li><strong>my_project\/<\/strong>\uff1a\u5b58\u653e\u9879\u76ee\u7684\u6e90\u4ee3\u7801\u3002<\/li>\n<li><strong>tests\/<\/strong>\uff1a\u5b58\u653e\u6d4b\u8bd5\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<p><h2>2\u3001\u521d\u59cb\u5316\u9879\u76ee<\/h2>\n<\/p>\n<p><p>\u5728\u521b\u5efa\u597d\u9879\u76ee\u7ed3\u6784\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u521d\u59cb\u5316\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u521b\u5efa\u9879\u76ee\u76ee\u5f55<\/p>\n<p>mkdir my_project<\/p>\n<p>cd my_project<\/p>\n<h2><strong>\u521b\u5efaREADME.md\u6587\u4ef6<\/strong><\/h2>\n<p>echo &quot;# My Project&quot; &gt; README.md<\/p>\n<h2><strong>\u521b\u5efasetup.py\u6587\u4ef6<\/strong><\/h2>\n<p>echo &quot;from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&#39;my_project&#39;,<\/p>\n<p>    version=&#39;0.1&#39;,<\/p>\n<p>    packages=find_packages(),<\/p>\n<p>    install_requires=[],<\/p>\n<p>)&quot; &gt; setup.py<\/p>\n<h2><strong>\u521b\u5efarequirements.txt\u6587\u4ef6<\/strong><\/h2>\n<p>touch requirements.txt<\/p>\n<h2><strong>\u521b\u5efa.gitignore\u6587\u4ef6<\/strong><\/h2>\n<p>echo &quot;venv\/<\/p>\n<p>__pycache__\/<\/p>\n<p>*.pyc<\/p>\n<p>*.pyo<\/p>\n<p>*.pyd<\/p>\n<p>*.swp<\/p>\n<p>*.swo<\/p>\n<p>&quot; &gt; .gitignore<\/p>\n<h2><strong>\u521b\u5efa\u9879\u76ee\u6e90\u4ee3\u7801\u76ee\u5f55<\/strong><\/h2>\n<p>mkdir my_project<\/p>\n<p>touch my_project\/__init__.py<\/p>\n<h2><strong>\u521b\u5efa\u6d4b\u8bd5\u76ee\u5f55<\/strong><\/h2>\n<p>mkdir tests<\/p>\n<p>touch tests\/__init__.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u5efa\u7acb\u4e86\u4e00\u4e2a\u57fa\u672c\u7684Python\u9879\u76ee\u7ed3\u6784\uff0c\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u548c\u6d4b\u8bd5\u4e86\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u56db\u3001\u521d\u59cb\u5316\u7248\u672c\u63a7\u5236<\/strong><\/h2>\n<p><p>\u7248\u672c\u63a7\u5236\u662f\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8ddf\u8e2a\u4ee3\u7801\u7684\u53d8\u5316\uff0c\u534f\u4f5c\u5f00\u53d1\uff0c\u5e76\u4e14\u53ef\u4ee5\u56de\u6eda\u5230\u4e4b\u524d\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u4e3a\u4ec0\u4e48\u4f7f\u7528\u7248\u672c\u63a7\u5236<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08VCS\uff09\u5982Git\uff0c\u53ef\u4ee5\u5e26\u6765\u4ee5\u4e0b\u597d\u5904\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u8ddf\u8e2a\u4ee3\u7801\u53d8\u5316<\/strong>\uff1a\u6bcf\u6b21\u63d0\u4ea4\u90fd\u4f1a\u8bb0\u5f55\u4ee3\u7801\u7684\u53d8\u5316\uff0c\u65b9\u4fbf\u67e5\u770b\u4fee\u6539\u5386\u53f2\u3002<\/li>\n<li><strong>\u534f\u4f5c\u5f00\u53d1<\/strong>\uff1a\u591a\u4e2a\u5f00\u53d1\u8005\u53ef\u4ee5\u540c\u65f6\u5de5\u4f5c\uff0c\u901a\u8fc7\u5206\u652f\u548c\u5408\u5e76\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u7ba1\u7406\u4e0d\u540c\u5f00\u53d1\u8005\u7684\u4ee3\u7801\u3002<\/li>\n<li><strong>\u7248\u672c\u56de\u6eda<\/strong>\uff1a\u5982\u679c\u5f15\u5165\u4e86\u9519\u8bef\uff0c\u53ef\u4ee5\u56de\u6eda\u5230\u4e4b\u524d\u7684\u7248\u672c\uff0c\u51cf\u5c11\u635f\u5931\u3002<\/li>\n<\/ul>\n<p><h2>2\u3001\u5982\u4f55\u521d\u59cb\u5316Git\u4ed3\u5e93<\/h2>\n<\/p>\n<p><p>\u521d\u59cb\u5316Git\u4ed3\u5e93\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5b89\u88c5Git\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09<\/p>\n<h2><strong>macOS<\/strong><\/h2>\n<p>brew install git<\/p>\n<h2><strong>Ubuntu<\/strong><\/h2>\n<p>sudo apt-get install git<\/p>\n<h2><strong>Windows<\/strong><\/h2>\n<p>choco install git<\/p>\n<h2><strong>\u521d\u59cb\u5316Git\u4ed3\u5e93<\/strong><\/h2>\n<p>git init<\/p>\n<h2><strong>\u6dfb\u52a0\u6240\u6709\u6587\u4ef6\u5230\u7248\u672c\u63a7\u5236<\/strong><\/h2>\n<p>git add .<\/p>\n<h2><strong>\u63d0\u4ea4\u521d\u59cb\u7248\u672c<\/strong><\/h2>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u521d\u59cb\u5316Git\u4ed3\u5e93\u540e\uff0c\u4f60\u53ef\u4ee5\u7ee7\u7eed\u8fdb\u884c\u5f00\u53d1\uff0c\u5b9a\u671f\u63d0\u4ea4\u4ee3\u7801\uff0c\u5e76\u4e14\u53ef\u4ee5\u521b\u5efa\u5206\u652f\u8fdb\u884c\u5b9e\u9a8c\u548c\u5f00\u53d1\u65b0\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u8fdc\u7a0b\u4ed3\u5e93<\/h2>\n<\/p>\n<p><p>\u5c06\u672c\u5730Git\u4ed3\u5e93\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff08\u5982GitHub\u3001GitLab\u6216Bitbucket\uff09\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5907\u4efd\u4ee3\u7801\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e0e\u56e2\u961f\u6210\u5458\u534f\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u521b\u5efa\u8fdc\u7a0b\u4ed3\u5e93\uff08\u4f8b\u5982\u5728GitHub\u4e0a\uff09<\/p>\n<h2><strong>\u7136\u540e\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684URL\u4e0e\u672c\u5730\u4ed3\u5e93\u5173\u8054<\/strong><\/h2>\n<p>git remote add origin https:\/\/github.com\/yourusername\/my_project.git<\/p>\n<h2><strong>\u63a8\u9001\u672c\u5730\u4ee3\u7801\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/strong><\/h2>\n<p>git push -u origin master<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u5730\u521d\u59cb\u5316\u4e86\u7248\u672c\u63a7\u5236\uff0c\u5e76\u4e14\u5c06\u672c\u5730\u4ee3\u7801\u63a8\u9001\u5230\u4e86\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e94\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56<\/strong><\/h2>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u5f88\u591a\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177\u3002\u4e3a\u4e86\u786e\u4fdd\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u4e00\u81f4\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u6765\u7ba1\u7406\u8fd9\u4e9b\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u6dfb\u52a0\u4f9d\u8d56\u5305<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528\u65b0\u7684\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230<code>requirements.txt<\/code>\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5b89\u88c5\u65b0\u7684\u4f9d\u8d56\u5305<\/p>\n<p>pip install requests<\/p>\n<h2><strong>\u5c06\u4f9d\u8d56\u5305\u6dfb\u52a0\u5230requirements.txt\u6587\u4ef6<\/strong><\/h2>\n<p>pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>pip freeze<\/code>\u547d\u4ee4\u4f1a\u5217\u51fa\u5f53\u524d\u865a\u62df\u73af\u5883\u4e2d\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5305\u53ca\u5176\u7248\u672c\uff0c\u5e76\u5c06\u5176\u5199\u5165<code>requirements.txt<\/code>\u6587\u4ef6\u3002\u8fd9\u6837\u5176\u4ed6\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u6587\u4ef6\u5b89\u88c5\u76f8\u540c\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u5b89\u88c5\u4f9d\u8d56\u5305<\/h2>\n<\/p>\n<p><p>\u5f53\u5176\u4ed6\u5f00\u53d1\u8005\u514b\u9686\u4f60\u7684\u9879\u76ee\u4ed3\u5e93\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u5b89\u88c5\u6240\u6709\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u521b\u5efa\u5e76\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/p>\n<p>python -m venv myenv<\/p>\n<p>source myenv\/bin\/activate<\/p>\n<h2><strong>\u5b89\u88c5\u4f9d\u8d56\u5305<\/strong><\/h2>\n<p>pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u786e\u4fdd\u6240\u6709\u5f00\u53d1\u8005\u4f7f\u7528\u76f8\u540c\u7248\u672c\u7684\u4f9d\u8d56\u5305\uff0c\u51cf\u5c11\u7531\u4e8e\u4f9d\u8d56\u7248\u672c\u4e0d\u4e00\u81f4\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u516d\u3001\u7f16\u5199\u548c\u6d4b\u8bd5\u4ee3\u7801<\/strong><\/h2>\n<p><p>\u7f16\u5199\u548c\u6d4b\u8bd5\u4ee3\u7801\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u6838\u5fc3\u90e8\u5206\u3002\u5728\u8fd9\u90e8\u5206\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u7f16\u5199\u9ad8\u8d28\u91cf\u7684\u4ee3\u7801\uff0c\u5e76\u901a\u8fc7\u81ea\u52a8\u5316\u6d4b\u8bd5\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u7f16\u5199\u9ad8\u8d28\u91cf\u7684\u4ee3\u7801<\/h2>\n<\/p>\n<p><p>\u7f16\u5199\u9ad8\u8d28\u91cf\u7684\u4ee3\u7801\u4e0d\u4ec5\u4ec5\u662f\u4f7f\u4ee3\u7801\u80fd\u591f\u8fd0\u884c\uff0c\u8fd8\u9700\u8981\u8003\u8651\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7f16\u5199\u9ad8\u8d28\u91cf\u4ee3\u7801\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u9075\u5faa\u4ee3\u7801\u98ce\u683c\u6307\u5357<\/strong>\uff1a\u9075\u5faaPEP 8\uff08Python\u7684\u4ee3\u7801\u98ce\u683c\u6307\u5357\uff09\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u4e00\u81f4\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/li>\n<li><strong>\u6a21\u5757\u5316<\/strong>\uff1a\u5c06\u4ee3\u7801\u62c6\u5206\u6210\u5c0f\u7684\u3001\u72ec\u7acb\u7684\u6a21\u5757\uff0c\u65b9\u4fbf\u7406\u89e3\u548c\u590d\u7528\u3002<\/li>\n<li><strong>\u6ce8\u91ca\u548c\u6587\u6863<\/strong>\uff1a\u5199\u6e05\u6670\u7684\u6ce8\u91ca\u548c\u6587\u6863\uff0c\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u4ee3\u7801\u3002<\/li>\n<li><strong>\u5f02\u5e38\u5904\u7406<\/strong>\uff1a\u5408\u7406\u5730\u5904\u7406\u5f02\u5e38\uff0c\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/li>\n<\/ul>\n<p><h2>2\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5<\/h2>\n<\/p>\n<p><p>\u81ea\u52a8\u5316\u6d4b\u8bd5\u662f\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf\u7684\u91cd\u8981\u624b\u6bb5\u3002Python\u6709\u591a\u4e2a\u6d4b\u8bd5\u6846\u67b6\u53ef\u4ee5\u9009\u62e9\uff0c\u5982unittest\u3001pytest\u548cnose\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528unittest\u7f16\u5199\u6d4b\u8bd5\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5728tests\u76ee\u5f55\u4e0b\u521b\u5efatest_sample.py\u6587\u4ef6<\/p>\n<p>import unittest<\/p>\n<p>from my_project import module1<\/p>\n<p>class TestModule1(unittest.TestCase):<\/p>\n<p>    def test_function1(self):<\/p>\n<p>        self.assertEqual(module1.function1(2, 3), 5)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528pytest\u7f16\u5199\u6d4b\u8bd5\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5728tests\u76ee\u5f55\u4e0b\u521b\u5efatest_sample.py\u6587\u4ef6<\/p>\n<p>import pytest<\/p>\n<p>from my_project import module1<\/p>\n<p>def test_function1():<\/p>\n<p>    assert module1.function1(2, 3) == 5<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    pytest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u5728\u4fee\u6539\u4ee3\u7801\u540e\u5feb\u901f\u9a8c\u8bc1\u5176\u6b63\u786e\u6027\uff0c\u51cf\u5c11\u5f15\u5165\u9519\u8bef\u7684\u98ce\u9669\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u6301\u7eed\u96c6\u6210<\/h2>\n<\/p>\n<p><p>\u6301\u7eed\u96c6\u6210\uff08CI\uff09\u662f\u4e00\u79cd\u8f6f\u4ef6\u5f00\u53d1\u5b9e\u8df5\uff0c\u901a\u8fc7\u81ea\u52a8\u5316\u6784\u5efa\u548c\u6d4b\u8bd5\u6765\u786e\u4fdd\u4ee3\u7801\u7684\u8d28\u91cf\u3002\u5e38\u7528\u7684CI\u5de5\u5177\u5305\u62ecTravis CI\u3001CircleCI\u548cJenkins\u3002<\/p>\n<\/p>\n<p><p>\u914d\u7f6eTravis CI\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa<code>.travis.yml<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-yaml\">language: python<\/p>\n<p>python:<\/p>\n<p>  - &quot;3.8&quot;<\/p>\n<p>install:<\/p>\n<p>  - pip install -r requirements.txt<\/p>\n<p>script:<\/p>\n<p>  - pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u9879\u76ee\u63a8\u9001\u5230GitHub\u540e\uff0cTravis CI\u4f1a\u81ea\u52a8\u6784\u5efa\u548c\u6d4b\u8bd5\u4ee3\u7801\uff0c\u5e76\u5728\u6bcf\u6b21\u63d0\u4ea4\u540e\u8fd0\u884c\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e03\u3001\u64b0\u5199\u6587\u6863<\/strong><\/h2>\n<p><p>\u64b0\u5199\u6587\u6863\u662f\u9879\u76ee\u5f00\u53d1\u7684\u91cd\u8981\u73af\u8282\uff0c\u5b83\u4e0d\u4ec5\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u548c\u4f7f\u7528\u4ee3\u7801\uff0c\u8fd8\u53ef\u4ee5\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u9879\u76ee\u6587\u6863<\/h2>\n<\/p>\n<p><p>\u9879\u76ee\u6587\u6863\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u9879\u76ee\u7b80\u4ecb<\/strong>\uff1a\u7b80\u8981\u4ecb\u7ecd\u9879\u76ee\u7684\u529f\u80fd\u548c\u76ee\u6807\u3002<\/li>\n<li><strong>\u5b89\u88c5\u6307\u5357<\/strong>\uff1a\u8be6\u7ec6\u8bf4\u660e\u5982\u4f55\u5b89\u88c5\u548c\u914d\u7f6e\u9879\u76ee\u3002<\/li>\n<li><strong>\u4f7f\u7528\u6307\u5357<\/strong>\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u4f7f\u7528\u793a\u4f8b\u548c\u8bf4\u660e\u3002<\/li>\n<li><strong>API\u6587\u6863<\/strong>\uff1a\u8be6\u7ec6\u8bf4\u660e\u9879\u76ee\u7684API\u63a5\u53e3\uff0c\u5305\u62ec\u8f93\u5165\u8f93\u51fa\u53c2\u6570\u3001\u793a\u4f8b\u4ee3\u7801\u7b49\u3002<\/li>\n<\/ul>\n<p><h2>2\u3001\u81ea\u52a8\u751f\u6210API\u6587\u6863<\/h2>\n<\/p>\n<p><p>Python\u6709\u591a\u4e2a\u5de5\u5177\u53ef\u4ee5\u7528\u4e8e\u81ea\u52a8\u751f\u6210API\u6587\u6863\uff0c\u5982Sphinx\u548cpdoc\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Sphinx\u751f\u6210API\u6587\u6863\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5b89\u88c5Sphinx<\/p>\n<p>pip install sphinx<\/p>\n<h2><strong>\u521b\u5efa\u6587\u6863\u76ee\u5f55<\/strong><\/h2>\n<p>mkdir docs<\/p>\n<p>cd docs<\/p>\n<h2><strong>\u521d\u59cb\u5316Sphinx\u9879\u76ee<\/strong><\/h2>\n<p>sphinx-quickstart<\/p>\n<h2><strong>\u4fee\u6539conf.py\u6587\u4ef6\uff0c\u6dfb\u52a0\u9879\u76ee\u8def\u5f84\u548c\u6a21\u5757\u540d<\/strong><\/h2>\n<p>import os<\/p>\n<p>import sys<\/p>\n<p>sys.path.insert(0, os.path.abspath(&#39;..\/my_project&#39;))<\/p>\n<h2><strong>\u751f\u6210API\u6587\u6863<\/strong><\/h2>\n<p>sphinx-apidoc -o . ..\/my_project<\/p>\n<h2><strong>\u6784\u5efaHTML\u6587\u6863<\/strong><\/h2>\n<p>make html<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u7684HTML\u6587\u6863\u53ef\u4ee5\u53d1\u5e03\u5230\u9879\u76ee\u7f51\u7ad9\uff0c\u4f9b\u7528\u6237\u67e5\u770b\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u64b0\u5199\u8be6\u7ec6\u7684\u6587\u6863\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u4e0a\u624b\u9879\u76ee\uff0c\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u516b\u3001\u90e8\u7f72\u548c\u7ef4\u62a4<\/strong><\/h2>\n<p><p>\u5728\u5b8c\u6210\u5f00\u53d1\u548c\u6d4b\u8bd5\u540e\uff0c\u9700\u8981\u5c06\u9879\u76ee\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff0c\u5e76\u8fdb\u884c\u6301\u7eed\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u90e8\u7f72\u9879\u76ee<\/h2>\n<\/p>\n<p><p>\u90e8\u7f72\u9879\u76ee\u7684\u6b65\u9aa4\u56e0\u9879\u76ee\u7c7b\u578b\u548c\u90e8\u7f72\u73af\u5883\u800c\u5f02\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u90e8\u7f72\u65b9\u5f0f\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>Web\u5e94\u7528\u90e8\u7f72<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Gunicorn\u548cNginx\u5c06Django\u6216Flask\u5e94\u7528\u90e8\u7f72\u5230\u670d\u52a1\u5668\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e91\u670d\u52a1\u5982Heroku\u3001AWS Elastic Beanstalk\u6216Google App Engine\u8fdb\u884c\u90e8\u7f72\u3002<\/li>\n<li><strong>\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u9879\u76ee\u90e8\u7f72<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Jupyter Notebook\u6216JupyterLab\u8fdb\u884c\u5c55\u793a\u548c\u5206\u4eab\u3002\u4e5f\u53ef\u4ee5\u5c06\u6a21\u578b\u90e8\u7f72\u4e3aWeb\u670d\u52a1\uff0c\u4f7f\u7528Flask\u6216FastAPI\u63d0\u4f9bAPI\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p><h2>2\u3001\u7ef4\u62a4\u9879\u76ee<\/h2>\n<\/p>\n<p><p>\u9879\u76ee\u90e8\u7f72\u540e\uff0c\u9700\u8981\u8fdb\u884c\u6301\u7eed\u7ef4\u62a4\uff0c\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u76d1\u63a7<\/strong>\uff1a\u4f7f\u7528\u76d1\u63a7\u5de5\u5177\u5982Prometheus\u548cGrafana\uff0c\u76d1\u63a7\u9879\u76ee\u7684\u8fd0\u884c\u72b6\u6001\u548c\u6027\u80fd\u3002<\/li>\n<li><strong>\u65e5\u5fd7\u8bb0\u5f55<\/strong>\uff1a\u4f7f\u7528\u65e5\u5fd7\u5de5\u5177\u5982Logstash\u548cElasticsearch\uff0c\u8bb0\u5f55\u9879\u76ee\u7684\u8fd0\u884c\u65e5\u5fd7\uff0c\u65b9\u4fbf\u6392\u67e5\u95ee\u9898\u3002<\/li>\n<li><strong>\u66f4\u65b0\u548c\u5347\u7ea7<\/strong>\uff1a\u5b9a\u671f\u66f4\u65b0\u9879\u76ee\u7684\u4f9d\u8d56\u5305\u548c\u6846\u67b6\uff0c\u4fee\u590d\u5b89\u5168\u6f0f\u6d1e\u548c\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7a33\u5b9a\u8fd0\u884c\uff0c\u5e76\u53ca\u65f6\u5e94\u5bf9\u5404\u79cd\u95ee\u9898\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e5d\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5efa\u7acb\u4e00\u4e2aPython\u9879\u76ee\u6d89\u53ca\u591a\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u521b\u5efa\u9879\u76ee\u7ed3\u6784\u3001\u521d\u59cb\u5316\u7248\u672c\u63a7\u5236\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u3001\u7f16\u5199\u548c\u6d4b\u8bd5\u4ee3\u7801\u3001\u64b0\u5199\u6587\u6863\u4ee5\u53ca\u90e8\u7f72\u548c\u7ef4\u62a4\u3002\u6bcf\u4e2a\u6b65\u9aa4\u90fd\u81f3\u5173\u91cd\u8981\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u9ad8\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u9009\u62e9\u9879\u76ee\u7c7b\u578b<\/strong>\uff1a\u660e\u786e\u9879\u76ee\u7684\u76ee\u6807\u548c\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u6846\u67b6\u3002<\/li>\n<li><strong>\u8bbe\u7f6e\u865a\u62df\u73af\u5883<\/strong>\uff1a\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u51b2\u7a81\u3002<\/li>\n<li><strong>\u521b\u5efa\u9879\u76ee\u7ed3\u6784<\/strong>\uff1a\u7ec4\u7ec7\u4ee3\u7801\uff0c\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<li><strong>\u521d\u59cb\u5316\u7248\u672c\u63a7\u5236<\/strong>\uff1a\u8ddf\u8e2a\u4ee3\u7801\u53d8\u5316\uff0c\u534f\u4f5c\u5f00\u53d1\u3002<\/li>\n<li><strong>\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56<\/strong>\uff1a\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5305\uff0c\u786e\u4fdd\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u7f16\u5199\u548c\u6d4b\u8bd5\u4ee3\u7801<\/strong>\uff1a\u7f16\u5199\u9ad8\u8d28\u91cf\u4ee3\u7801\uff0c\u8fdb\u884c\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002<\/li>\n<li><strong>\u64b0\u5199\u6587\u6863<\/strong>\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u4f7f\u7528\u8bf4\u660e\u548cAPI\u6587\u6863\u3002<\/li>\n<li><strong>\u90e8\u7f72\u548c\u7ef4\u62a4<\/strong>\uff1a\u5c06\u9879\u76ee\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff0c\u8fdb\u884c\u6301\u7eed\u76d1\u63a7\u548c\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u5f00\u53d1Python\u9879\u76ee\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u9879\u76ee\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u9002\u5408\u7684Python\u9879\u76ee\u7ed3\u6784\uff1f<\/strong><br \/>\u5728\u5efa\u7acbPython\u9879\u76ee\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u9879\u76ee\u7ed3\u6784\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u9879\u76ee\u7ed3\u6784\u5305\u62ec\u6e90\u4ee3\u7801\u76ee\u5f55\uff08\u901a\u5e38\u547d\u540d\u4e3a<code>src<\/code>\u6216\u9879\u76ee\u540d\u79f0\uff09\uff0c\u6d4b\u8bd5\u76ee\u5f55\uff08<code>tests<\/code>\uff09\uff0c\u914d\u7f6e\u6587\u4ef6\uff08\u5982<code>requirements.txt<\/code>\u6216<code>setup.py<\/code>\uff09\uff0c\u4ee5\u53ca\u6587\u6863\u76ee\u5f55\u3002\u8fd9\u6837\u7684\u7ed3\u6784\u6709\u52a9\u4e8e\u4ee3\u7801\u7684\u7ec4\u7ec7\u548c\u7ef4\u62a4\uff0c\u540c\u65f6\u4e5f\u65b9\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u548c\u53c2\u4e0e\u9879\u76ee\u3002<\/p>\n<p><strong>\u5728Python\u9879\u76ee\u4e2d\u5982\u4f55\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\uff1f<\/strong><br \/>\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\u6765\u5b9e\u73b0\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u5217\u51fa\u6240\u6709\u7684\u4f9d\u8d56\u5305\u53ca\u5176\u7248\u672c\u53f7\uff0c\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u547d\u4ee4\u5c31\u53ef\u4ee5\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982<code>venv<\/code>\u6216<code>conda<\/code>\uff09\u53ef\u4ee5\u5e2e\u52a9\u9694\u79bb\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u9879\u76ee\u4e2d\u8fdb\u884c\u7248\u672c\u63a7\u5236\uff1f<\/strong><br \/>\u4f7f\u7528Git\u4f5c\u4e3a\u7248\u672c\u63a7\u5236\u5de5\u5177\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\u3002\u9996\u5148\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u521d\u59cb\u5316\u4e00\u4e2aGit\u4ed3\u5e93\uff08<code>git init<\/code>\uff09\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528<code>.gitignore<\/code>\u6587\u4ef6\u6765\u6392\u9664\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6\u548c\u76ee\u5f55\uff08\u5982<code>__pycache__<\/code>\u3001\u865a\u62df\u73af\u5883\u7b49\uff09\u3002\u5b9a\u671f\u63d0\u4ea4\u4ee3\u7801\uff0c\u5e76\u4f7f\u7528\u5206\u652f\u7ba1\u7406\u4e0d\u540c\u7684\u529f\u80fd\u5f00\u53d1\uff0c\u8fd9\u6837\u53ef\u4ee5\u6709\u6548\u5730\u8ddf\u8e2a\u9879\u76ee\u8fdb\u5ea6\u548c\u53d8\u66f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u5efa\u7acb\u9879\u76ee\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u521b\u5efa\u9879\u76ee\u7ed3\u6784\u3001\u521d\u59cb\u5316\u7248\u672c\u63a7\u5236\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u3001\u7f16 [&hellip;]","protected":false},"author":3,"featured_media":1174571,"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\/1174564"}],"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=1174564"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174564\/revisions"}],"predecessor-version":[{"id":1174572,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174564\/revisions\/1174572"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1174571"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1174564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1174564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1174564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}