{"id":1095956,"date":"2025-01-08T14:56:26","date_gmt":"2025-01-08T06:56:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1095956.html"},"modified":"2025-01-08T14:56:29","modified_gmt":"2025-01-08T06:56:29","slug":"%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85python%e4%ba%8c%e8%bf%9b%e5%88%b6%e5%8c%85-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1095956.html","title":{"rendered":"\u5982\u4f55\u5b89\u88c5python\u4e8c\u8fdb\u5236\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211356\/541809f8-0208-4853-ad55-427f8b88c6c6.webp\" alt=\"\u5982\u4f55\u5b89\u88c5python\u4e8c\u8fdb\u5236\u5305\" \/><\/p>\n<p><p> <strong>\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u6b63\u786e\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3001\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88c5\u5305\u3001\u9a8c\u8bc1\u5b89\u88c5\u3002<\/strong> \u5176\u4e2d\uff0c\u9009\u62e9\u6b63\u786e\u7684\u5305\u7ba1\u7406\u5de5\u5177\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u5305\u7ba1\u7406\u5de5\u5177\u6709\u4e0d\u540c\u7684\u64cd\u4f5c\u65b9\u5f0f\u548c\u4f9d\u8d56\u5904\u7406\u65b9\u5f0f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u7684\u5404\u4e2a\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u9009\u62e9\u6b63\u786e\u7684\u5305\u7ba1\u7406\u5de5\u5177<\/strong><\/h2>\n<p><p>\u5728\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002\u5e38\u89c1\u7684Python\u5305\u7ba1\u7406\u5de5\u5177\u6709pip\u3001conda\u548cwheel\u3002<strong>pip\u662fPython\u5b98\u65b9\u63a8\u8350\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u9002\u5408\u5927\u90e8\u5206\u573a\u666f\uff1bconda\u5219\u9002\u7528\u4e8eAnaconda\u73af\u5883\uff0c\u5177\u6709\u66f4\u5f3a\u5927\u7684\u73af\u5883\u7ba1\u7406\u80fd\u529b\uff1bwheel\u662f\u4e00\u79cdPython\u4e8c\u8fdb\u5236\u5305\u683c\u5f0f\uff0c\u901a\u5e38\u4e0epip\u4e00\u8d77\u4f7f\u7528\u3002<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>pip<\/strong>\uff1apip\u662fPython\u5b98\u65b9\u63a8\u8350\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u652f\u6301PyPI\uff08Python Package Index\uff09\u4e0a\u7684\u5927\u90e8\u5206\u5305\u3002\u5b83\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u5927\u90e8\u5206\u7528\u6237\u3002<\/li>\n<li><strong>conda<\/strong>\uff1aconda\u662fAnaconda\u73af\u5883\u4e0b\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u9664\u4e86Python\u5305\uff0c\u8fd8\u53ef\u4ee5\u7ba1\u7406\u5176\u4ed6\u8bed\u8a00\u7684\u5305\u548c\u4f9d\u8d56\u3002\u5b83\u9002\u7528\u4e8e\u9700\u8981\u591a\u8bed\u8a00\u73af\u5883\u548c\u6570\u636e\u79d1\u5b66\u7684\u7528\u6237\u3002<\/li>\n<li><strong>wheel<\/strong>\uff1awheel\u662f\u4e00\u79cdPython\u4e8c\u8fdb\u5236\u5305\u683c\u5f0f\uff0c\u4e0epip\u914d\u5408\u4f7f\u7528\u80fd\u591f\u52a0\u5feb\u5b89\u88c5\u901f\u5ea6\u3002\u5b83\u53ef\u4ee5\u907f\u514d\u5728\u5b89\u88c5\u65f6\u7f16\u8bd1\u6e90\u4ee3\u7801\uff0c\u9002\u7528\u4e8e\u5927\u578b\u9879\u76ee\u548c\u4f9d\u8d56\u8f83\u591a\u7684\u5305\u3002<\/li>\n<\/ol>\n<h2><strong>\u4e8c\u3001\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305<\/strong><\/h2>\n<p><p>\u5728\u9009\u62e9\u4e86\u5408\u9002\u7684\u5305\u7ba1\u7406\u5de5\u5177\u540e\uff0c\u9700\u8981\u83b7\u53d6\u9700\u8981\u5b89\u88c5\u7684Python\u4e8c\u8fdb\u5236\u5305\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7d\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u5305\u6216\u8005\u76f4\u63a5\u4ece\u5305\u7ba1\u7406\u5de5\u5177\u7684\u4ed3\u5e93\u4e2d\u83b7\u53d6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4ecePyPI\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305<\/strong>\uff1a\u4f7f\u7528pip\u53ef\u4ee5\u76f4\u63a5\u4ecePyPI\u4e0b\u8f7d\u548c\u5b89\u88c5\u4e8c\u8fdb\u5236\u5305\u3002PyPI\u662fPython\u5b98\u65b9\u7684\u5305\u7ba1\u7406\u4ed3\u5e93\uff0c\u5305\u542b\u4e86\u5927\u91cf\u7684Python\u5305\u3002<\/li>\n<li><strong>\u4eceAnaconda\u4ed3\u5e93\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305<\/strong>\uff1a\u4f7f\u7528conda\u53ef\u4ee5\u4eceAnaconda\u5b98\u65b9\u4ed3\u5e93\u6216\u8005\u5176\u4ed6\u955c\u50cf\u4ed3\u5e93\u4e0b\u8f7d\u548c\u5b89\u88c5\u4e8c\u8fdb\u5236\u5305\u3002<\/li>\n<li><strong>\u4e0b\u8f7d\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u5305<\/strong>\uff1a\u6709\u4e9b\u5305\u7684\u5b98\u65b9\u7f51\u7ad9\u4f1a\u63d0\u4f9b\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u5305\uff0c\u53ef\u4ee5\u76f4\u63a5\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u4e00\u4e9b\u7279\u6b8a\u7684\u5305\u6216\u8005\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684\u60c5\u51b5\u3002<\/li>\n<\/ol>\n<h2><strong>\u4e09\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88c5\u5305<\/strong><\/h2>\n<p><p>\u83b7\u53d6\u4e86\u4e8c\u8fdb\u5236\u5305\u540e\uff0c\u63a5\u4e0b\u6765\u5c31\u662f\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u6b65\u9aa4\u56e0\u5de5\u5177\u4e0d\u540c\u800c\u6709\u6240\u533a\u522b\u3002<\/p>\n<\/p>\n<p><h2>1. \u4f7f\u7528pip\u5b89\u88c5\u4e8c\u8fdb\u5236\u5305<\/h2>\n<\/p>\n<p><p>pip\u662fPython\u5b98\u65b9\u63a8\u8350\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u4f7f\u7528\u975e\u5e38\u7b80\u4fbf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install package_name==version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5b89\u88c5wheel\u683c\u5f0f\u7684\u4e8c\u8fdb\u5236\u5305<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0b\u8f7d\u4e86wheel\u683c\u5f0f\u7684\u4e8c\u8fdb\u5236\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install path\/to\/package_name.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2. \u4f7f\u7528conda\u5b89\u88c5\u4e8c\u8fdb\u5236\u5305<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f7f\u7528\u7684\u662fAnaconda\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528conda\u8fdb\u884c\u5b89\u88c5\u3002conda\u652f\u6301\u4eceAnaconda\u4ed3\u5e93\u6216\u8005\u5176\u4ed6\u955c\u50cf\u4ed3\u5e93\u4e0b\u8f7d\u548c\u5b89\u88c5\u4e8c\u8fdb\u5236\u5305\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">conda install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u7248\u672c\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">conda install package_name=version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3. \u76f4\u63a5\u5b89\u88c5\u4e0b\u8f7d\u7684\u4e8c\u8fdb\u5236\u5305<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4ece\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u4e86\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install path\/to\/package_name.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/h2>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9700\u8981\u9a8c\u8bc1\u5305\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u8fdb\u884c\u9a8c\u8bc1\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528pip show\u547d\u4ee4<\/strong>\uff1a\u53ef\u4ee5\u67e5\u770b\u5305\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u3001\u4f9d\u8d56\u7b49\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">pip show package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5728Python\u89e3\u91ca\u5668\u4e2d\u5bfc\u5165\u5305<\/strong>\uff1a\u53ef\u4ee5\u5728Python\u89e3\u91ca\u5668\u4e2d\u5c1d\u8bd5\u5bfc\u5165\u5305\uff0c\u5982\u679c\u6ca1\u6709\u62a5\u9519\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u67e5\u770b\u5b89\u88c5\u76ee\u5f55<\/strong>\uff1a\u53ef\u4ee5\u67e5\u770bPython\u7684site-packages\u76ee\u5f55\uff0c\u786e\u8ba4\u5305\u662f\u5426\u5b58\u5728\u3002<\/li>\n<\/ol>\n<h2><strong>\u4e94\u3001\u89e3\u51b3\u5b89\u88c5\u95ee\u9898<\/strong><\/h2>\n<p><p>\u5728\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7f51\u7edc\u95ee\u9898<\/strong>\uff1a\u5728\u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u9047\u5230\u7f51\u7edc\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6362\u955c\u50cf\u6e90\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u56fd\u5185\u7684\u955c\u50cf\u6e90\u52a0\u5feb\u4e0b\u8f7d\u901f\u5ea6\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">pip install -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a\u6709\u4e9b\u5305\u53ef\u80fd\u9700\u8981\u5176\u4ed6\u4f9d\u8d56\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u7684<code>--no-deps<\/code>\u9009\u9879\u5ffd\u7565\u4f9d\u8d56\uff0c\u5e76\u624b\u52a8\u5b89\u88c5\u6240\u9700\u4f9d\u8d56\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">pip install package_name --no-deps<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5728\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u53ef\u80fd\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u624d\u80fd\u5b89\u88c5\u5305\u3002\u53ef\u4ee5\u4f7f\u7528<code>sudo<\/code>\u547d\u4ee4\u63d0\u5347\u6743\u9650\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">sudo pip install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u517c\u5bb9\u6027\u95ee\u9898<\/strong>\uff1a\u6709\u4e9b\u5305\u53ef\u80fd\u4e0e\u5f53\u524dPython\u7248\u672c\u4e0d\u517c\u5bb9\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5b89\u88c5\u5176\u4ed6\u7248\u672c\u7684\u5305\u6216\u8005\u66f4\u65b0Python\u7248\u672c\u3002<\/li>\n<\/ol>\n<h2><strong>\u516d\u3001\u6700\u4f73\u5b9e\u8df5<\/strong><\/h2>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406Python\u5305\uff0c\u5efa\u8bae\u9075\u5faa\u4ee5\u4e0b\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08virtualenv\u6216venv\uff09\u6765\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\uff0c\u907f\u514d\u5305\u7248\u672c\u51b2\u7a81\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">python -m venv myenv<\/p>\n<p>source myenv\/bin\/activate  # Linux\u548cmacOS<\/p>\n<p>myenv\\Scripts\\activate  # Windows<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528requirements.txt<\/strong>\uff1a\u53ef\u4ee5\u5c06\u9879\u76ee\u4f9d\u8d56\u5199\u5165requirements.txt\u6587\u4ef6\uff0c\u65b9\u4fbf\u5176\u4ed6\u4eba\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">pip freeze &gt; requirements.txt<\/p>\n<p>pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b9a\u671f\u66f4\u65b0\u5305<\/strong>\uff1a\u5b9a\u671f\u66f4\u65b0\u5305\u548c\u4f9d\u8d56\uff0c\u786e\u4fdd\u9879\u76ee\u4f7f\u7528\u6700\u65b0\u7684\u7248\u672c\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">pip install --upgrade package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u4f7f\u7528\u7a33\u5b9a\u7248\u672c<\/strong>\uff1a\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u5efa\u8bae\u4f7f\u7528\u7a33\u5b9a\u7248\u672c\u7684\u5305\uff0c\u907f\u514d\u4f7f\u7528\u6d4b\u8bd5\u7248\u6216\u8005\u5f00\u53d1\u7248\u3002<\/li>\n<\/ol>\n<h2><strong>\u4e03\u3001\u4f7f\u7528Docker\u7ba1\u7406\u4f9d\u8d56<\/strong><\/h2>\n<p><p>\u5bf9\u4e8e\u590d\u6742\u9879\u76ee\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Docker\u6765\u7ba1\u7406\u4f9d\u8d56\u548c\u73af\u5883\u3002Docker\u53ef\u4ee5\u521b\u5efa\u72ec\u7acb\u7684\u5bb9\u5668\uff0c\u786e\u4fdd\u9879\u76ee\u73af\u5883\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efaDockerfile<\/strong>\uff1a\u7f16\u5199Dockerfile\uff0c\u5b9a\u4e49\u57fa\u7840\u955c\u50cf\u548c\u4f9d\u8d56\u5305\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-Dockerfile\">FROM python:3.8-slim<\/p>\n<p>WORKDIR \/app<\/p>\n<p>COPY requirements.txt .<\/p>\n<p>RUN pip install --no-cache-dir -r requirements.txt<\/p>\n<p>COPY . .<\/p>\n<p>CMD [&quot;python&quot;, &quot;app.py&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6784\u5efa\u955c\u50cf<\/strong>\uff1a\u4f7f\u7528Docker\u547d\u4ee4\u6784\u5efa\u955c\u50cf\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">docker build -t myapp .<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u8fd0\u884c\u5bb9\u5668<\/strong>\uff1a\u4f7f\u7528Docker\u547d\u4ee4\u8fd0\u884c\u5bb9\u5668\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-shell\">docker run -d -p 8000:8000 myapp<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516b\u3001\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\u5de5\u5177\u81ea\u52a8\u5316\u5305\u7ba1\u7406<\/strong><\/h2>\n<p><p>\u5728\u56e2\u961f\u534f\u4f5c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528CI\/CD\u5de5\u5177\uff08\u5982Jenkins\u3001GitLab CI\u3001GitHub Actions\uff09\u6765\u81ea\u52a8\u5316\u5305\u7ba1\u7406\u548c\u90e8\u7f72\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u7f16\u5199CI\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a\u5728\u9879\u76ee\u4e2d\u7f16\u5199CI\u914d\u7f6e\u6587\u4ef6\uff0c\u5b9a\u4e49\u5b89\u88c5\u6b65\u9aa4\u548c\u6d4b\u8bd5\u6d41\u7a0b\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-yaml\">name: CI<\/p>\n<p>on: [push]<\/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 pip install --upgrade pip<\/p>\n<p>        pip install -r requirements.txt<\/p>\n<p>    - name: Run tests<\/p>\n<p>      run: |<\/p>\n<p>        pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u96c6\u6210CI\u5de5\u5177<\/strong>\uff1a\u5c06\u9879\u76ee\u4e0eCI\u5de5\u5177\u96c6\u6210\uff0c\u786e\u4fdd\u6bcf\u6b21\u63d0\u4ea4\u4ee3\u7801\u65f6\u81ea\u52a8\u6267\u884c\u5b89\u88c5\u548c\u6d4b\u8bd5\u6d41\u7a0b\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u786e\u4fddPython\u4e8c\u8fdb\u5236\u5305\u7684\u6b63\u786e\u5b89\u88c5\u548c\u7ba1\u7406\u3002\u4f7f\u7528\u6b63\u786e\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3001\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305\u3001\u5b89\u88c5\u5305\u3001\u9a8c\u8bc1\u5b89\u88c5\u3001\u89e3\u51b3\u5b89\u88c5\u95ee\u9898\u3001\u9075\u5faa\u6700\u4f73\u5b9e\u8df5\u3001\u4f7f\u7528Docker\u7ba1\u7406\u4f9d\u8d56\u3001\u4f7f\u7528CI\/CD\u5de5\u5177\u81ea\u52a8\u5316\u5305\u7ba1\u7406\uff0c\u662f\u5b89\u88c5\u548c\u7ba1\u7406Python\u4e8c\u8fdb\u5236\u5305\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684\u7cfb\u7edf\u662f\u5426\u5df2\u7ecf\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u5982\u679c\u7cfb\u7edf\u8fd4\u56de\u4e86\u7248\u672c\u53f7\uff0c\u8bf4\u660ePython\u5df2\u7ecf\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u4f60\u9700\u8981\u5148\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\u3002<\/p>\n<p><strong>\u5728\u54ea\u4e9b\u5e73\u53f0\u4e0a\u53ef\u4ee5\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\uff1f<\/strong><br \/>Python\u4e8c\u8fdb\u5236\u5305\u53ef\u4ee5\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fdb\u884c\u5b89\u88c5\uff0c\u5305\u62ecWindows\u3001macOS\u548cLinux\u3002\u6bcf\u4e2a\u5e73\u53f0\u7684\u5b89\u88c5\u6b65\u9aa4\u53ef\u80fd\u7565\u6709\u4e0d\u540c\uff0c\u56e0\u6b64\u5728\u4e0b\u8f7d\u65f6\u9700\u9009\u62e9\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u76f8\u5bf9\u5e94\u7684\u7248\u672c\u3002\u6b64\u5916\uff0c\u67d0\u4e9bLinux\u53d1\u884c\u7248\u53ef\u80fd\u4f1a\u63d0\u4f9bPython\u7684\u9884\u88c5\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u7684\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u4e8c\u8fdb\u5236\u5305\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684Python\u4e8c\u8fdb\u5236\u5305\u9700\u8003\u8651\u51e0\u4e2a\u65b9\u9762\uff0c\u5305\u62ecPython\u7684\u7248\u672c\u3001\u64cd\u4f5c\u7cfb\u7edf\u53ca\u5176\u67b6\u6784\uff08\u598232\u4f4d\u621664\u4f4d\uff09\u3002\u901a\u5e38\uff0cPython\u5b98\u65b9\u7f51\u7ad9\u548c\u7b2c\u4e09\u65b9\u5e93\uff08\u5982PyPI\uff09\u90fd\u4f1a\u63d0\u4f9b\u4e0d\u540c\u7248\u672c\u7684\u4e8c\u8fdb\u5236\u5305\u3002\u5728\u4e0b\u8f7d\u4e4b\u524d\uff0c\u52a1\u5fc5\u786e\u8ba4\u8fd9\u4e9b\u4fe1\u606f\uff0c\u4ee5\u786e\u4fdd\u6240\u4e0b\u8f7d\u7684\u5305\u4e0e\u60a8\u7684\u73af\u5883\u517c\u5bb9\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528pip\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\uff1f<\/strong><br \/>\u4f7f\u7528pip\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u975e\u5e38\u7b80\u5355\u3002\u53ea\u9700\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u547d\u4ee4<code>pip install package_name<\/code>\uff08\u5c06<code>package_name<\/code>\u66ff\u6362\u4e3a\u4f60\u8981\u5b89\u88c5\u7684\u5305\u540d\uff09\uff0cpip\u4f1a\u81ea\u52a8\u4ecePython\u5305\u7d22\u5f15\uff08PyPI\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684\u8be5\u5305\u3002\u5982\u679c\u4f60\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install package_name==version<\/code>\u6765\u6307\u5b9a\u7248\u672c\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b89\u88c5Python\u4e8c\u8fdb\u5236\u5305\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u6b63\u786e\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3001\u83b7\u53d6\u4e8c\u8fdb\u5236\u5305\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88c5\u5305\u3001\u9a8c\u8bc1\u5b89\u88c5\u3002 \u5176\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":1095963,"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\/1095956"}],"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=1095956"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095956\/revisions"}],"predecessor-version":[{"id":1095968,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095956\/revisions\/1095968"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1095963"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1095956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1095956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1095956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}