{"id":926576,"date":"2024-12-26T15:53:25","date_gmt":"2024-12-26T07:53:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/926576.html"},"modified":"2024-12-26T15:53:27","modified_gmt":"2024-12-26T07:53:27","slug":"%e5%a6%82%e4%bd%95%e5%8f%91%e5%b8%83python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/926576.html","title":{"rendered":"\u5982\u4f55\u53d1\u5e03python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25063119\/c6841cb9-ec04-4194-b9d1-379b346a6cdb.webp\" alt=\"\u5982\u4f55\u53d1\u5e03python\" \/><\/p>\n<p><p> <strong>\u53d1\u5e03Python\u9879\u76ee\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u51c6\u5907\u9879\u76ee\u3001\u521b\u5efa\u8bf4\u660e\u6587\u6863\u3001\u9009\u62e9\u5408\u9002\u7684\u5e73\u53f0\u3001\u6253\u5305\u9879\u76ee\u3001\u53d1\u5e03\u7248\u672c<\/strong>\u3002\u5176\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e73\u53f0\u662f\u5173\u952e\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u5e73\u53f0\u9488\u5bf9\u4e0d\u540c\u7684\u7528\u6237\u7fa4\u4f53\u548c\u9700\u6c42\u3002\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u4f60\u7684\u9879\u76ee\u7684\u5e73\u53f0\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u63a8\u5e7f\u548c\u5206\u53d1\u4f60\u7684\u4ee3\u7801\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u4e2a\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u51c6\u5907\u9879\u76ee<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u53d1\u5e03Python\u9879\u76ee\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u5df2\u7ecf\u51c6\u5907\u597d\u3002\u8fd9\u610f\u5473\u7740\u4f60\u9700\u8981\u6709\u4e00\u4e2a\u529f\u80fd\u5b8c\u6574\u7684\u4ee3\u7801\u5e93\uff0c\u5e76\u8fdb\u884c\u5145\u5206\u7684\u6d4b\u8bd5\u3002\u4ee5\u4e0b\u662f\u51c6\u5907\u9879\u76ee\u7684\u4e00\u4e9b\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4ee3\u7801\u6574\u7406<\/strong>\uff1a\u786e\u4fdd\u4ee3\u7801\u6574\u6d01\uff0c\u53bb\u9664\u5197\u4f59\u4ee3\u7801\u548c\u4e0d\u5fc5\u8981\u7684\u8c03\u8bd5\u4fe1\u606f\u3002\u9075\u5faaPython\u7684\u7f16\u7801\u89c4\u8303\uff0c\u5982PEP 8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5<\/strong>\uff1a\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u6765\u9a8c\u8bc1\u4ee3\u7801\u7684\u529f\u80fd\uff0c\u786e\u4fdd\u4ee3\u7801\u5728\u5404\u79cd\u60c5\u51b5\u4e0b\u90fd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u6d4b\u8bd5\u662f\u4fdd\u8bc1\u9879\u76ee\u8d28\u91cf\u7684\u91cd\u8981\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f9d\u8d56\u9879\u7ba1\u7406<\/strong>\uff1a\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u6216<code>Pipfile<\/code>\u6765\u5217\u51fa\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u9879\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u521b\u5efa\u8bf4\u660e\u6587\u6863<\/p>\n<\/p>\n<p><p>\u826f\u597d\u7684\u6587\u6863\u662f\u7528\u6237\u7406\u89e3\u548c\u4f7f\u7528\u4f60\u9879\u76ee\u7684\u5173\u952e\u3002\u521b\u5efa\u6e05\u6670\u7684\u8bf4\u660e\u6587\u6863\uff0c\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9879\u76ee\u7b80\u4ecb<\/strong>\uff1a\u7b80\u8981\u63cf\u8ff0\u9879\u76ee\u7684\u76ee\u7684\u3001\u529f\u80fd\u548c\u7279\u70b9\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u6307\u5357<\/strong>\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u5b89\u88c5\u6b65\u9aa4\uff0c\u5305\u62ec\u4f9d\u8d56\u9879\u7684\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u8bf4\u660e<\/strong>\uff1a\u89e3\u91ca\u5982\u4f55\u4f7f\u7528\u9879\u76ee\u7684\u4e3b\u8981\u529f\u80fd\uff0c\u6700\u597d\u5305\u62ec\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8d21\u732e\u6307\u5357<\/strong>\uff1a\u5982\u679c\u4f60\u5e0c\u671b\u4ed6\u4eba\u8d21\u732e\u4ee3\u7801\u6216\u63d0\u51fa\u5efa\u8bae\uff0c\u63d0\u4f9b\u8d21\u732e\u6d41\u7a0b\u548c\u89c4\u5219\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bb8\u53ef\u8bc1<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff0c\u5e76\u5c06\u5176\u5305\u542b\u5728\u9879\u76ee\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u9009\u62e9\u5408\u9002\u7684\u5e73\u53f0<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u53d1\u5e03\u5e73\u53f0\u662f\u6210\u529f\u7684\u5173\u952e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684Python\u9879\u76ee\u53d1\u5e03\u5e73\u53f0\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyPI (Python Package Index)<\/strong>\uff1a\u8fd9\u662fPython\u5b98\u65b9\u7684\u5305\u7ba1\u7406\u5e73\u53f0\uff0c\u9002\u5408\u53d1\u5e03Python\u5e93\u548c\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>GitHub<\/strong>\uff1a\u9002\u5408\u6258\u7ba1\u5f00\u6e90\u9879\u76ee\u4ee3\u7801\uff0c\u53ef\u4ee5\u7ed3\u5408GitHub\u7684\u7248\u672c\u63a7\u5236\u548c\u534f\u4f5c\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Conda<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u9879\u76ee\u4f9d\u8d56\u4e8e\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0cConda\u53ef\u80fd\u662f\u4e00\u4e2a\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Docker Hub<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u9879\u76ee\u9700\u8981\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\uff0c\u53ef\u4ee5\u5c06\u5176\u6253\u5305\u4e3aDocker\u955c\u50cf\u5e76\u53d1\u5e03\u5230Docker Hub\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6253\u5305\u9879\u76ee<\/p>\n<\/p>\n<p><p>\u6253\u5305\u9879\u76ee\u662f\u53d1\u5e03\u7684\u5173\u952e\u6b65\u9aa4\u3002\u4f7f\u7528<code>setuptools<\/code>\u6216<code>poetry<\/code>\u7b49\u5de5\u5177\u6765\u6253\u5305\u4f60\u7684Python\u9879\u76ee\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa<code>setup.py<\/code>\u6587\u4ef6<\/strong>\uff1a\u8fd9\u662f\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u9879\u76ee\u540d\u79f0\u3001\u7248\u672c\u3001\u63cf\u8ff0\u3001\u4f5c\u8005\u3001\u4f9d\u8d56\u9879\u7b49\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u5206\u53d1\u5305<\/strong>\uff1a\u4f7f\u7528<code>python setup.py sdist bdist_wheel<\/code>\u547d\u4ee4\u751f\u6210\u6e90\u4ee3\u7801\u5305\u548cWheel\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5\u5305<\/strong>\uff1a\u5728\u672c\u5730\u6216\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u5e76\u6d4b\u8bd5\u751f\u6210\u7684\u5305\uff0c\u786e\u4fdd\u5176\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u53d1\u5e03\u7248\u672c<\/p>\n<\/p>\n<p><p>\u9879\u76ee\u6253\u5305\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u53d1\u5e03\u5230\u9009\u62e9\u7684\u5e73\u53f0\u4e0a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53d1\u5e03\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u53d1\u5e03\u5230PyPI<\/strong>\uff1a\u4f7f\u7528<code>twine upload dist\/*<\/code>\u547d\u4ee4\u5c06\u5305\u4e0a\u4f20\u5230PyPI\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u53d1\u5e03\u5230GitHub<\/strong>\uff1a\u521b\u5efa\u4e00\u4e2aGitHub Release\uff0c\u5e76\u4e0a\u4f20\u6784\u5efa\u7684\u5305\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u63a7\u5236<\/strong>\uff1a\u6839\u636e\u9879\u76ee\u7684\u53d8\u5316\uff0c\u4f7f\u7528\u8bed\u4e49\u5316\u7248\u672c\u53f7\uff08\u59821.0.0\uff09\u6765\u6807\u8bb0\u6bcf\u6b21\u53d1\u5e03\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u65b0\u65e5\u5fd7<\/strong>\uff1a\u5728\u6bcf\u6b21\u53d1\u5e03\u65f6\uff0c\u66f4\u65b0\u9879\u76ee\u7684\u66f4\u65b0\u65e5\u5fd7\uff0c\u8bb0\u5f55\u65b0\u529f\u80fd\u3001\u4fee\u590d\u548c\u6539\u8fdb\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u6210\u529f\u5730\u53d1\u5e03\u4e00\u4e2aPython\u9879\u76ee\u3002\u53d1\u5e03\u540e\uff0c\u7ee7\u7eed\u5173\u6ce8\u7528\u6237\u53cd\u9988\u548c\u9879\u76ee\u7ef4\u62a4\uff0c\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u6301\u7eed\u53d1\u5c55\u548c\u6539\u8fdb\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u53d1\u5e03\u5e73\u53f0\u6765\u53d1\u5e03\u6211\u7684Python\u9879\u76ee\uff1f<\/strong><br \/>\u9009\u62e9\u53d1\u5e03\u5e73\u53f0\u65f6\uff0c\u8003\u8651\u9879\u76ee\u7684\u6027\u8d28\u548c\u76ee\u6807\u53d7\u4f17\u975e\u5e38\u91cd\u8981\u3002\u5bf9\u4e8e\u5f00\u6e90\u9879\u76ee\uff0cGitHub\u548cGitLab\u662f\u53d7\u6b22\u8fce\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u4eec\u63d0\u4f9b\u7248\u672c\u63a7\u5236\u548c\u793e\u533a\u4e92\u52a8\u529f\u80fd\u3002\u5982\u679c\u4f60\u7684\u9879\u76ee\u662f\u5546\u4e1a\u6027\u8d28\uff0cPyPI\uff08Python Package Index\uff09\u662f\u4e00\u4e2a\u7406\u60f3\u7684\u5e73\u53f0\uff0c\u53ef\u4ee5\u8ba9\u7528\u6237\u8f7b\u677e\u5b89\u88c5\u4f60\u7684\u5e93\u3002\u6b64\u5916\uff0cDocker Hub\u4e5f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5bb9\u5668\u5316\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p><strong>\u5728\u53d1\u5e03Python\u9879\u76ee\u4e4b\u524d\u9700\u8981\u8fdb\u884c\u54ea\u4e9b\u51c6\u5907\u5de5\u4f5c\uff1f<\/strong><br \/>\u53d1\u5e03\u524d\uff0c\u786e\u4fdd\u9879\u76ee\u4ee3\u7801\u7ecf\u8fc7\u5145\u5206\u6d4b\u8bd5\u5e76\u4e14\u6587\u6863\u9f50\u5168\u3002\u5199\u6e05\u6670\u7684README\u6587\u4ef6\uff0c\u8bf4\u660e\u9879\u76ee\u7684\u5b89\u88c5\u548c\u4f7f\u7528\u65b9\u6cd5\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u5de5\u5177\u5982<code>setuptools<\/code>\u4e3a\u4f60\u7684\u5305\u521b\u5efa\u4e00\u4e2a<code>setup.py<\/code>\u6587\u4ef6\uff0c\u4ee5\u4fbf\u7528\u6237\u80fd\u591f\u8f7b\u677e\u5b89\u88c5\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u4f9d\u8d56\u5173\u7cfb\u5e76\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u5e93\u90fd\u5df2\u5217\u51fa\uff0c\u8fd9\u6837\u7528\u6237\u5728\u5b89\u88c5\u65f6\u4e0d\u4f1a\u9047\u5230\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u6211\u7684Python\u9879\u76ee\u5728\u53d1\u5e03\u540e\u80fd\u591f\u5f97\u5230\u7528\u6237\u7684\u5173\u6ce8\u548c\u4f7f\u7528\uff1f<\/strong><br \/>\u5728\u53d1\u5e03\u540e\uff0c\u901a\u8fc7\u793e\u4ea4\u5a92\u4f53\u3001\u5f00\u53d1\u8005\u8bba\u575b\u548c\u76f8\u5173\u793e\u533a\u8fdb\u884c\u63a8\u5e7f\u662f\u589e\u52a0\u9879\u76ee\u66dd\u5149\u5ea6\u7684\u6709\u6548\u65b9\u5f0f\u3002\u64b0\u5199\u535a\u5ba2\u6587\u7ae0\u6216\u5f55\u5236\u89c6\u9891\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u9879\u76ee\u7684\u529f\u80fd\u548c\u4f7f\u7528\u6848\u4f8b\uff0c\u53ef\u4ee5\u5438\u5f15\u66f4\u591a\u7528\u6237\u5173\u6ce8\u3002\u6b64\u5916\uff0c\u53c2\u4e0e\u4e0e\u9879\u76ee\u76f8\u5173\u7684\u5f00\u6e90\u6d3b\u52a8\u6216\u4f1a\u8bae\uff0c\u80fd\u591f\u8ba9\u66f4\u591a\u4eba\u4e86\u89e3\u5e76\u4f7f\u7528\u4f60\u7684\u9879\u76ee\u3002\u9f13\u52b1\u7528\u6237\u53cd\u9988\u548c\u8d21\u732e\u4e5f\u662f\u63d0\u5347\u9879\u76ee\u77e5\u540d\u5ea6\u7684\u597d\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u53d1\u5e03Python\u9879\u76ee\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u51c6\u5907\u9879\u76ee\u3001\u521b\u5efa\u8bf4\u660e\u6587\u6863\u3001\u9009\u62e9\u5408\u9002\u7684\u5e73\u53f0\u3001\u6253\u5305\u9879\u76ee\u3001\u53d1\u5e03\u7248\u672c\u3002\u5176\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e73 [&hellip;]","protected":false},"author":3,"featured_media":926580,"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\/926576"}],"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=926576"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/926576\/revisions"}],"predecessor-version":[{"id":926582,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/926576\/revisions\/926582"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/926580"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=926576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=926576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=926576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}