{"id":1120319,"date":"2025-01-08T18:54:56","date_gmt":"2025-01-08T10:54:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1120319.html"},"modified":"2025-01-08T18:55:00","modified_gmt":"2025-01-08T10:55:00","slug":"%e5%a6%82%e4%bd%95%e5%88%9b%e5%bb%bapython%e7%9a%84%e8%84%9a%e6%9c%ac%e6%96%87%e4%bb%b6%e5%a4%b9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1120319.html","title":{"rendered":"\u5982\u4f55\u521b\u5efapython\u7684\u811a\u672c\u6587\u4ef6\u5939"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083019\/14ded075-7088-4398-80c3-c8b781f65aa0.webp\" alt=\"\u5982\u4f55\u521b\u5efapython\u7684\u811a\u672c\u6587\u4ef6\u5939\" \/><\/p>\n<p><p> <strong>\u521b\u5efaPython\u811a\u672c\u6587\u4ef6\u5939\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u6587\u4ef6\u5939\u540d\u79f0\u3001\u7ec4\u7ec7\u6587\u4ef6\u7ed3\u6784\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u6dfb\u52a0\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u3001\u7f16\u5199\u811a\u672c\u5e76\u6d4b\u8bd5\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<strong>\u7ec4\u7ec7\u6587\u4ef6\u7ed3\u6784<\/strong>\u5c24\u4e3a\u91cd\u8981\u3002\u4e00\u4e2a\u826f\u597d\u7684\u6587\u4ef6\u7ed3\u6784\u4e0d\u4ec5\u6709\u52a9\u4e8e\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u7ef4\u62a4\u6027\uff0c\u8fd8\u80fd\u4f7f\u9879\u76ee\u66f4\u52a0\u6a21\u5757\u5316\u548c\u53ef\u6269\u5c55\u3002\u6807\u51c6\u7684Python\u9879\u76ee\u6587\u4ef6\u7ed3\u6784\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u76ee\u5f55\u548c\u6587\u4ef6\uff1a<code>src<\/code>\uff08\u5b58\u653e\u6e90\u4ee3\u7801\uff09\u3001<code>tests<\/code>\uff08\u5b58\u653e\u6d4b\u8bd5\u4ee3\u7801\uff09\u3001<code>docs<\/code>\uff08\u5b58\u653e\u6587\u6863\uff09\u3001<code>requirements.txt<\/code>\uff08\u5217\u51fa\u9879\u76ee\u4f9d\u8d56\u7684\u5e93\uff09\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u548c\u7ec4\u7ec7Python\u811a\u672c\u6587\u4ef6\u5939\uff0c\u5e76\u9010\u6b65\u8bb2\u89e3\u6bcf\u4e2a\u6b65\u9aa4\u7684\u5177\u4f53\u5185\u5bb9\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u6587\u4ef6\u5939\u540d\u79f0<\/strong><\/h2>\n<p><p>\u5728\u521b\u5efaPython\u811a\u672c\u6587\u4ef6\u5939\u65f6\uff0c\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u4e14\u6709\u610f\u4e49\u7684\u540d\u79f0\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u6587\u4ef6\u5939\u540d\u79f0\u5e94\u80fd\u6e05\u6670\u5730\u8868\u8fbe\u9879\u76ee\u7684\u76ee\u7684\u6216\u5185\u5bb9\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u786e\u4fdd\u540d\u79f0\u7b80\u6d01\u660e\u4e86<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6587\u4ef6\u5939\u540d\u79f0\u5e94\u5c3d\u91cf\u7b80\u77ed\uff0c\u4f46\u8981\u80fd\u6982\u62ec\u9879\u76ee\u7684\u4e3b\u8981\u529f\u80fd\u6216\u7279\u6027\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5f00\u53d1\u4e00\u4e2a\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06\u6587\u4ef6\u5939\u547d\u540d\u4e3a<code>data_analysis_tool<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9075\u5faa\u547d\u540d\u89c4\u8303<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u5206\u9694\u5355\u8bcd\u3002\u8fd9\u79cd\u547d\u540d\u65b9\u5f0f\u5728Python\u793e\u533a\u4e2d\u88ab\u5e7f\u6cdb\u63a5\u53d7\uff0c\u6709\u52a9\u4e8e\u4fdd\u6301\u4e00\u81f4\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u907f\u514d\u5728\u6587\u4ef6\u5939\u540d\u79f0\u4e2d\u4f7f\u7528\u7a7a\u683c\u3001\u7279\u6b8a\u5b57\u7b26\u6216\u5b57\u6bcd\u7684\u6df7\u5408\u5f62\u5f0f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u6216\u5de5\u5177\u4e2d\u5f15\u53d1\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u4e8c\u3001\u7ec4\u7ec7\u6587\u4ef6\u7ed3\u6784<\/strong><\/h2>\n<p><p>\u4e00\u4e2a\u826f\u597d\u7684\u6587\u4ef6\u7ed3\u6784\u80fd\u591f\u4f7f\u9879\u76ee\u66f4\u52a0\u6a21\u5757\u5316\u548c\u53ef\u6269\u5c55\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5e38\u89c1\u7684Python\u9879\u76ee\u6587\u4ef6\u7ed3\u6784\uff1a<\/p>\n<\/p>\n<p><pre><code>project_name\/<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 src\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 module1.py<\/p>\n<p>\u2502   \u2514\u2500\u2500 module2.py<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 tests\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 test_module1.py<\/p>\n<p>\u2502   \u2514\u2500\u2500 test_module2.py<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 docs\/<\/p>\n<p>\u2502   \u2514\u2500\u2500 README.md<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 requirements.txt<\/p>\n<p>\u2514\u2500\u2500 setup.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol>\n<li>\n<p><strong>src\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b58\u653e\u9879\u76ee\u7684\u6e90\u4ee3\u7801\u3002<code>__init__.py<\/code>\u6587\u4ef6\u7528\u4e8e\u5c06\u76ee\u5f55\u6807\u8bb0\u4e3aPython\u5305\u3002<code>main.py<\/code>\u901a\u5e38\u662f\u9879\u76ee\u7684\u5165\u53e3\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>tests\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b58\u653e\u6d4b\u8bd5\u4ee3\u7801\u3002\u53ef\u4ee5\u4f7f\u7528<code>unittest<\/code>\u3001<code>pytest<\/code>\u7b49\u6d4b\u8bd5\u6846\u67b6\u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>docs\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b58\u653e\u9879\u76ee\u7684\u6587\u6863\u3002\u901a\u5e38\u5305\u542b\u4e00\u4e2a<code>README.md<\/code>\u6587\u4ef6\uff0c\u4ecb\u7ecd\u9879\u76ee\u7684\u80cc\u666f\u3001\u5b89\u88c5\u6b65\u9aa4\u3001\u4f7f\u7528\u65b9\u6cd5\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>requirements.txt\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5217\u51fa\u9879\u76ee\u6240\u4f9d\u8d56\u7684\u7b2c\u4e09\u65b9\u5e93\u53ca\u5176\u7248\u672c\u3002\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5\u4f9d\u8d56\u9879\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u8be5\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>setup.py\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u8ba1\u5212\u5c06\u9879\u76ee\u6253\u5305\u53d1\u5e03\uff0c\u53ef\u4ee5\u7f16\u5199<code>setup.py<\/code>\u6587\u4ef6\uff0c\u5305\u542b\u9879\u76ee\u7684\u5143\u6570\u636e\u548c\u914d\u7f6e\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u4e09\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<p><p>\u5728\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u9879\uff0c\u907f\u514d\u4e0e\u5168\u5c40Python\u73af\u5883\u7684\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a\n<pre><code class=\"language-bash\">python3 -m venv venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u4e0d\u540c\uff1a\n<ul>\n<li>Windows:\n<pre><code class=\"language-bash\">venv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>macOS\u548cLinux:\n<pre><code class=\"language-bash\">source venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u9879<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002\u4f8b\u5982\uff1a\n<pre><code class=\"language-bash\">pip install numpy pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u751f\u6210requirements.txt\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u9879\u540e\uff0c\u53ef\u4ee5\u751f\u6210<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u8bb0\u5f55\u4f9d\u8d56\u9879\u53ca\u5176\u7248\u672c\uff1a\n<pre><code class=\"language-bash\">pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u56db\u3001\u7f16\u5199\u811a\u672c\u5e76\u6d4b\u8bd5<\/strong><\/h2>\n<p><p>\u7f16\u5199Python\u811a\u672c\u5e76\u8fdb\u884c\u6d4b\u8bd5\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u6700\u6838\u5fc3\u7684\u90e8\u5206\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\u548c\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u53ef\u8bfb\u6027\u5f3a\u7684\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9075\u5faaPEP 8\u7f16\u7801\u89c4\u8303\uff0c\u7f16\u5199\u6e05\u6670\u3001\u7b80\u6d01\u7684\u4ee3\u7801\u3002\u4f7f\u7528\u6709\u610f\u4e49\u7684\u53d8\u91cf\u540d\u548c\u51fd\u6570\u540d\uff0c\u6dfb\u52a0\u9002\u5f53\u7684\u6ce8\u91ca\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6a21\u5757\u5316\u7f16\u7a0b<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5c06\u4ee3\u7801\u5212\u5206\u4e3a\u591a\u4e2a\u6a21\u5757\uff0c\u6bcf\u4e2a\u6a21\u5757\u8d1f\u8d23\u4e00\u4e2a\u72ec\u7acb\u7684\u529f\u80fd\u3002\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u590d\u7528\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u5355\u5143\u6d4b\u8bd5<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4e3a\u6bcf\u4e2a\u6a21\u5757\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002\u53ef\u4ee5\u4f7f\u7528<code>unittest<\/code>\u3001<code>pytest<\/code>\u7b49\u6d4b\u8bd5\u6846\u67b6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u6d4b\u8bd5<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6267\u884c\u6d4b\u8bd5\u4ee3\u7801\uff1a\n<pre><code class=\"language-bash\">pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u4e94\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf<\/strong><\/h2>\n<p><p>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982Git\uff09\u53ef\u4ee5\u8ddf\u8e2a\u4ee3\u7801\u7684\u53d8\u5316\uff0c\u534f\u4f5c\u5f00\u53d1\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u7ba1\u7406\u6548\u7387\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521d\u59cb\u5316Git\u4ed3\u5e93<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u521d\u59cb\u5316Git\u4ed3\u5e93\uff1a\n<pre><code class=\"language-bash\">git init<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa.gitignore\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a<code>.gitignore<\/code>\u6587\u4ef6\uff0c\u5ffd\u7565\u4e0d\u9700\u8981\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002\u4f8b\u5982\uff1a\n<pre><code class=\"language-plaintext\">venv\/<\/p>\n<p>__pycache__\/<\/p>\n<p>*.pyc<\/p>\n<p>.DS_Store<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u63d0\u4ea4\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6dfb\u52a0\u548c\u63d0\u4ea4\u4ee3\u7801\u5230Git\u4ed3\u5e93\uff1a\n<pre><code class=\"language-bash\">git add .<\/p>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fdc\u7a0b\u4ed3\u5e93<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u4f7f\u7528GitHub\u3001GitLab\u7b49\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u53ef\u4ee5\u5c06\u672c\u5730\u4ed3\u5e93\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u5173\u8054\uff0c\u5e76\u63a8\u9001\u4ee3\u7801\uff1a\n<pre><code class=\"language-bash\">git remote add origin &lt;remote_repository_url&gt;<\/p>\n<p>git push -u origin master<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u516d\u3001\u9879\u76ee\u6587\u6863\u548c\u8bf4\u660e<\/strong><\/h2>\n<p><p>\u826f\u597d\u7684\u6587\u6863\u548c\u8bf4\u660e\u80fd\u591f\u5e2e\u52a9\u4ed6\u4eba\u5feb\u901f\u7406\u89e3\u548c\u4f7f\u7528\u4f60\u7684\u9879\u76ee\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>README.md\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728<code>docs<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa<code>README.md<\/code>\u6587\u4ef6\uff0c\u4ecb\u7ecd\u9879\u76ee\u7684\u80cc\u666f\u3001\u5b89\u88c5\u6b65\u9aa4\u3001\u4f7f\u7528\u65b9\u6cd5\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528Markdown\u8bed\u6cd5\u7f16\u5199\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ee3\u7801\u6ce8\u91ca<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u9002\u5f53\u7684\u6ce8\u91ca\uff0c\u89e3\u91ca\u5173\u952e\u903b\u8f91\u548c\u51fd\u6570\u7684\u7528\u9014\u3002\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>API\u6587\u6863<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u9879\u76ee\u5305\u542b\u591a\u4e2a\u6a21\u5757\u548c\u51fd\u6570\uff0c\u53ef\u4ee5\u751f\u6210API\u6587\u6863\uff0c\u8be6\u7ec6\u63cf\u8ff0\u6bcf\u4e2a\u6a21\u5757\u548c\u51fd\u6570\u7684\u529f\u80fd\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528Sphinx\u7b49\u5de5\u5177\u751f\u6210API\u6587\u6863\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u63d0\u4f9b\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u9879\u76ee\u4e2d\u7684\u529f\u80fd\u3002\u53ef\u4ee5\u5728<code>docs<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>examples<\/code>\u5b50\u76ee\u5f55\uff0c\u5b58\u653e\u793a\u4f8b\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u4e03\u3001\u9879\u76ee\u6253\u5305\u548c\u53d1\u5e03<\/strong><\/h2>\n<p><p>\u5982\u679c\u4f60\u5e0c\u671b\u5c06\u9879\u76ee\u53d1\u5e03\u5230PyPI\uff08Python Package Index\uff09\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u6253\u5305\u548c\u53d1\u5e03\u9879\u76ee\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199setup.py\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa<code>setup.py<\/code>\u6587\u4ef6\uff0c\u5305\u542b\u9879\u76ee\u7684\u5143\u6570\u636e\u548c\u914d\u7f6e\u4fe1\u606f\u3002\u4f8b\u5982\uff1a\n<pre><code class=\"language-python\">from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&#39;project_name&#39;,<\/p>\n<p>    version=&#39;0.1.0&#39;,<\/p>\n<p>    description=&#39;A brief description of the project&#39;,<\/p>\n<p>    author=&#39;Your Name&#39;,<\/p>\n<p>    author_email=&#39;your.email@example.com&#39;,<\/p>\n<p>    packages=find_packages(where=&#39;src&#39;),<\/p>\n<p>    package_dir={&#39;&#39;: &#39;src&#39;},<\/p>\n<p>    install_requires=[<\/p>\n<p>        &#39;numpy&#39;,<\/p>\n<p>        &#39;pandas&#39;,<\/p>\n<p>    ],<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u751f\u6210\u5206\u53d1\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u751f\u6210\u5206\u53d1\u6587\u4ef6\uff1a\n<pre><code class=\"language-bash\">python setup.py sdist bdist_wheel<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u53d1\u5e03\u5230PyPI<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528twine\u5de5\u5177\u5c06\u5206\u53d1\u6587\u4ef6\u4e0a\u4f20\u5230PyPI\uff1a\n<pre><code class=\"language-bash\">pip install twine<\/p>\n<p>twine upload dist\/*<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><strong>\u516b\u3001\u6301\u7eed\u96c6\u6210\u548c\u90e8\u7f72<\/strong><\/h2>\n<p><p>\u6301\u7eed\u96c6\u6210\u548c\u90e8\u7f72\uff08<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\uff09\u53ef\u4ee5\u81ea\u52a8\u5316\u6d4b\u8bd5\u548c\u53d1\u5e03\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9CI\u5de5\u5177<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9009\u62e9\u4e00\u4e2aCI\u5de5\u5177\uff08\u5982GitHub Actions\u3001Travis CI\u3001CircleCI\u7b49\uff09\uff0c\u6839\u636e\u9879\u76ee\u9700\u6c42\u914d\u7f6eCI\u6d41\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efaCI\u5de5\u5177\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5b9a\u4e49\u6d4b\u8bd5\u548c\u53d1\u5e03\u6b65\u9aa4\u3002\u4f8b\u5982\uff0c\u4f7f\u7528GitHub Actions\u65f6\uff0c\u53ef\u4ee5\u5728<code>.github\/workflows<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>ci.yml<\/code>\u6587\u4ef6\uff1a\n<pre><code class=\"language-yaml\">name: CI<\/p>\n<p>on: [push, pull_request]<\/p>\n<p>jobs:<\/p>\n<p>  build:<\/p>\n<p>    runs-on: ubuntu-latest<\/p>\n<p>    steps:<\/p>\n<p>    - uses: actions\/checkout@v2<\/p>\n<p>    - name: Set up Python<\/p>\n<p>      uses: actions\/setup-python@v2<\/p>\n<p>      with:<\/p>\n<p>        python-version: 3.8<\/p>\n<p>    - name: Install dependencies<\/p>\n<p>      run: |<\/p>\n<p>        python -m venv venv<\/p>\n<p>        source venv\/bin\/activate<\/p>\n<p>        pip install -r requirements.txt<\/p>\n<p>    - name: Run tests<\/p>\n<p>      run: |<\/p>\n<p>        source venv\/bin\/activate<\/p>\n<p>        pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u53d1\u5e03<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u914d\u7f6eCI\u5de5\u5177\uff0c\u5728\u901a\u8fc7\u6240\u6709\u6d4b\u8bd5\u540e\uff0c\u81ea\u52a8\u5316\u53d1\u5e03\u65b0\u7248\u672c\u5230PyPI\u6216\u5176\u4ed6\u5305\u7ba1\u7406\u5e73\u53f0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7ed3\u6784\u5408\u7406\u3001\u529f\u80fd\u5b8c\u5584\u7684Python\u811a\u672c\u6587\u4ef6\u5939\uff0c\u5e76\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4fdd\u6301\u4ee3\u7801\u7684\u9ad8\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u811a\u672c\u6587\u4ef6\u5939\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u4e2d\u7684<code>mkdir<\/code>\u6216<code>makedirs<\/code>\u51fd\u6570\u6765\u521b\u5efa\u65b0\u7684\u6587\u4ef6\u5939\u3002\u4f60\u53ea\u9700\u5bfc\u5165<code>os<\/code>\u6a21\u5757\u5e76\u8c03\u7528\u76f8\u5e94\u7684\u51fd\u6570\uff0c\u63d0\u4f9b\u4f60\u60f3\u8981\u521b\u5efa\u7684\u6587\u4ef6\u5939\u8def\u5f84\u3002\u5982\u679c\u9700\u8981\u4e00\u6b21\u6027\u521b\u5efa\u591a\u5c42\u6587\u4ef6\u5939\uff0c\u4f7f\u7528<code>makedirs<\/code>\u4f1a\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<p><strong>\u521b\u5efa\u6587\u4ef6\u5939\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6743\u9650\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u521b\u5efa\u6587\u4ef6\u5939\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u6709\u8db3\u591f\u7684\u6743\u9650\u5728\u76ee\u6807\u8def\u5f84\u4e0b\u8fdb\u884c\u64cd\u4f5c\u3002\u5982\u679c\u5728\u67d0\u4e9b\u53d7\u9650\u7684\u76ee\u5f55\u4e2d\u5c1d\u8bd5\u521b\u5efa\u6587\u4ef6\u5939\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4<code>PermissionError<\/code>\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8003\u8651\u9009\u62e9\u4e00\u4e2a\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u6216\u8005\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u521b\u5efa\u6587\u4ef6\u5939\u7684\u540c\u65f6\u521b\u5efaPython\u811a\u672c\u6587\u4ef6\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u521b\u5efa\u6587\u4ef6\u5939\u540e\uff0c\u5229\u7528<code>open<\/code>\u51fd\u6570\u521b\u5efaPython\u811a\u672c\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5148\u521b\u5efa\u6587\u4ef6\u5939\uff0c\u7136\u540e\u5728\u8be5\u6587\u4ef6\u5939\u5185\u521b\u5efa\u4e00\u4e2a<code>.py<\/code>\u6587\u4ef6\u3002\u786e\u4fdd\u5728\u521b\u5efa\u6587\u4ef6\u4e4b\u524d\uff0c\u76ee\u6807\u6587\u4ef6\u5939\u5df2\u7ecf\u5b58\u5728\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u3002<\/p>\n<p><strong>\u5982\u4f55\u68c0\u67e5\u6587\u4ef6\u5939\u662f\u5426\u5df2\u5b58\u5728\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u521b\u5efa\uff1f<\/strong><br \/>\u5728\u521b\u5efa\u6587\u4ef6\u5939\u4e4b\u524d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os.path.exists<\/code>\u51fd\u6570\u6765\u68c0\u67e5\u76ee\u6807\u8def\u5f84\u662f\u5426\u5df2\u5b58\u5728\u3002\u5982\u679c\u8fd4\u56de\u503c\u4e3a<code>True<\/code>\uff0c\u5219\u8868\u793a\u6587\u4ef6\u5939\u5df2\u7ecf\u5b58\u5728\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u8df3\u8fc7\u521b\u5efa\u6216\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u521b\u5efaPython\u811a\u672c\u6587\u4ef6\u5939\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u6587\u4ef6\u5939\u540d\u79f0\u3001\u7ec4\u7ec7\u6587\u4ef6\u7ed3\u6784\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u6dfb\u52a0\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u3001\u7f16\u5199 [&hellip;]","protected":false},"author":3,"featured_media":1120322,"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\/1120319"}],"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=1120319"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120319\/revisions"}],"predecessor-version":[{"id":1120323,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120319\/revisions\/1120323"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1120322"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1120319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1120319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1120319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}