{"id":1182993,"date":"2025-01-15T19:09:31","date_gmt":"2025-01-15T11:09:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1182993.html"},"modified":"2025-01-15T19:09:34","modified_gmt":"2025-01-15T11:09:34","slug":"python%e6%97%a0%e7%bd%91%e7%bb%9c%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1182993.html","title":{"rendered":"python\u65e0\u7f51\u7edc\u5982\u4f55\u5b89\u88c5\u6a21\u5757"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25132917\/91ef0868-2170-466f-bbe6-b100ce69e92a.webp\" alt=\"python\u65e0\u7f51\u7edc\u5982\u4f55\u5b89\u88c5\u6a21\u5757\" \/><\/p>\n<p><p> <strong>\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5Python\u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u79bb\u7ebf\u5b89\u88c5\u5305\u3001\u62f7\u8d1d\u5df2\u6709\u73af\u5883\u3001\u4f7f\u7528\u672c\u5730\u955c\u50cf\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u79bb\u7ebf\u5b89\u88c5\u5305<\/strong>\uff1a\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4ece\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u4e0b\u8f7d\u6240\u9700\u6a21\u5757\u7684\u79bb\u7ebf\u5b89\u88c5\u5305\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u5305\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u79bb\u7ebf\u5b89\u88c5\u5305<\/h3>\n<\/p>\n<p><h4>1\u3001\u4e0b\u8f7d\u6240\u9700\u6a21\u5757\u7684\u79bb\u7ebf\u5b89\u88c5\u5305<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5728\u4e00\u53f0\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u7535\u8111\u4e0a\u4e0b\u8f7d\u6240\u9700\u7684Python\u6a21\u5757\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u8fdb\u884c\u4e0b\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip download &lt;module_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6761\u547d\u4ee4\u4f1a\u4e0b\u8f7d\u6a21\u5757\u7684\u6240\u6709\u4f9d\u8d56\u5305\uff0c\u5e76\u751f\u6210<code>.whl<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u53ef\u4ee5\u5728\u6ca1\u6709\u7f51\u7edc\u7684\u7535\u8111\u4e0a\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5c06\u5b89\u88c5\u5305\u4f20\u8f93\u5230\u76ee\u6807\u8ba1\u7b97\u673a<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528U\u76d8\u3001\u79fb\u52a8\u786c\u76d8\u6216\u5176\u4ed6\u6570\u636e\u4f20\u8f93\u5de5\u5177\u5c06\u4e0b\u8f7d\u7684\u5305\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u5728\u6ca1\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5c06\u4e0b\u8f7d\u7684\u5305\u4f20\u8f93\u5230\u76ee\u6807\u8ba1\u7b97\u673a\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install &lt;module_name&gt;.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u9010\u4e2a\u5b89\u88c5\u4e0b\u8f7d\u597d\u7684\u5305\uff0c\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5173\u7cfb\u90fd\u80fd\u6ee1\u8db3\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u62f7\u8d1d\u5df2\u6709\u73af\u5883<\/h3>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u73b0\u6709\u73af\u5883\u7684\u526f\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u7535\u8111\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip freeze<\/code>\u547d\u4ee4\u5bfc\u51fa\u5f53\u524d\u73af\u5883\u4e2d\u7684\u6240\u6709\u6a21\u5757\u53ca\u5176\u7248\u672c\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5b89\u88c5\u76f8\u540c\u7684\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5c06\u751f\u6210\u7684<code>requirements.txt<\/code>\u6587\u4ef6\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u7535\u8111\u4e0a\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt --no-index --find-links=\/path\/to\/whl_files<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d<code>--no-index<\/code>\u53c2\u6570\u544a\u8bc9<code>pip<\/code>\u4e0d\u8981\u4f7f\u7528\u7f51\u7edc\u4e0a\u7684PyPI\u4ed3\u5e93\uff0c\u800c<code>--find-links<\/code>\u53c2\u6570\u6307\u5b9a\u672c\u5730\u7684<code>.whl<\/code>\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u672c\u5730\u955c\u50cf<\/h3>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u672c\u5730\u955c\u50cf<\/h4>\n<\/p>\n<p><p>\u5728\u6709\u7f51\u7edc\u7684\u7535\u8111\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip download<\/code>\u547d\u4ee4\u4e0b\u8f7d\u6240\u6709\u6a21\u5757\u548c\u4f9d\u8d56\u5305\uff0c\u5e76\u5c06\u5b83\u4eec\u653e\u5728\u4e00\u4e2a\u672c\u5730\u76ee\u5f55\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip download -d \/path\/to\/local_mirror &lt;module_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5728\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u4f7f\u7528\u672c\u5730\u955c\u50cf<\/h4>\n<\/p>\n<p><p>\u5c06\u4e0b\u8f7d\u7684\u5305\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --no-index --find-links=\/path\/to\/local_mirror &lt;module_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c<code>pip<\/code>\u5c06\u4ece\u672c\u5730\u955c\u50cf\u4e2d\u5b89\u88c5\u6a21\u5757\uff0c\u800c\u4e0d\u662f\u5c1d\u8bd5\u4ece\u7f51\u7edc\u4e0a\u4e0b\u8f7d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177<\/h3>\n<\/p>\n<p><h4>1\u3001Conda<\/h4>\n<\/p>\n<p><p>Conda\u662f\u4e00\u4e2a\u5f00\u6e90\u8f6f\u4ef6\u5305\u7ba1\u7406\u7cfb\u7edf\u548c\u73af\u5883\u7ba1\u7406\u7cfb\u7edf\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b89\u88c5\u3001\u8fd0\u884c\u548c\u66f4\u65b0\u5305\u548c\u4f9d\u8d56\u9879\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u73af\u5883\u7684\u5feb\u7167\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda list --export &gt; environment.yml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u7535\u8111\u4e0a\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6062\u590d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda env create -f environment.yml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528Wheel\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>Wheel\u6587\u4ef6\u662f\u4e00\u79cdPython\u5206\u53d1\u683c\u5f0f\uff0c\u53ef\u4ee5\u52a0\u5feb\u5b89\u88c5\u901f\u5ea6\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip wheel<\/code>\u547d\u4ee4\u521b\u5efaWheel\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip wheel &lt;module_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5c06\u751f\u6210\u7684Wheel\u6587\u4ef6\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u7684\u7535\u8111\u4e0a\uff0c\u4f7f\u7528<code>pip install<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install &lt;module_name&gt;.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u624b\u52a8\u5b89\u88c5<\/h3>\n<\/p>\n<p><h4>1\u3001\u4e0b\u8f7d\u6e90\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4ece\u5b98\u65b9\u7f51\u7ad9\u6216\u4ed3\u5e93\u4e0b\u8f7d\u6240\u9700\u6a21\u5757\u7684\u6e90\u4ee3\u7801\u5305\uff0c\u4e00\u822c\u662f<code>.tar.gz<\/code>\u6216<code>.zip<\/code>\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f20\u8f93\u6e90\u4ee3\u7801\u5305<\/h4>\n<\/p>\n<p><p>\u5c06\u6e90\u4ee3\u7801\u5305\u4f20\u8f93\u5230\u6ca1\u6709\u7f51\u7edc\u7684\u7535\u8111\u4e0a\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u89e3\u538b\u5e76\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u89e3\u538b\u6e90\u4ee3\u7801\u5305\uff0c\u7136\u540e\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u6240\u6709Python\u6a21\u5757\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5Python\u6a21\u5757\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u79bb\u7ebf\u5b89\u88c5\u5305\u3001\u62f7\u8d1d\u5df2\u6709\u73af\u5883\u3001\u4f7f\u7528\u672c\u5730\u955c\u50cf\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u4ee5\u53ca\u624b\u52a8\u5b89\u88c5\u3002<strong>\u9009\u62e9\u9002\u5408\u81ea\u5df1\u60c5\u51b5\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u89e3\u51b3\u5728\u65e0\u7f51\u7edc\u73af\u5883\u4e0b\u5b89\u88c5Python\u6a21\u5757\u7684\u95ee\u9898<\/strong>\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6ca1\u6709\u7f51\u7edc\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5Python\u6a21\u5757\uff1f<\/strong><br \/>\u5728\u6ca1\u6709\u7f51\u7edc\u7684\u73af\u5883\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u9884\u5148\u4e0b\u8f7d\u6240\u9700\u7684Python\u6a21\u5757\u53ca\u5176\u4f9d\u8d56\u9879\u6765\u8fdb\u884c\u5b89\u88c5\u3002\u60a8\u53ef\u4ee5\u5728\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u4f7f\u7528<code>pip download<\/code>\u547d\u4ee4\u4e0b\u8f7d\u6a21\u5757\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u6587\u4ef6\u8f6c\u79fb\u5230\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5b89\u88c5\u3002\u4f7f\u7528\u547d\u4ee4\u5982<code>pip download &lt;module_name&gt;<\/code>\u53ef\u4ee5\u5c06\u6a21\u5757\u53ca\u5176\u4f9d\u8d56\u9879\u4e0b\u8f7d\u4e3a.whl\u6216.tar.gz\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n<p><strong>\u9700\u8981\u54ea\u4e9b\u51c6\u5907\u5de5\u4f5c\u624d\u80fd\u5728\u79bb\u7ebf\u73af\u5883\u4e2d\u5b89\u88c5\u6a21\u5757\uff1f<\/strong><br \/>\u60a8\u9700\u8981\u51c6\u5907\u4e00\u4e2a\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\uff0c\u5e76\u786e\u4fdd\u5b89\u88c5\u4e86Python\u548cpip\u3002\u5728\u8be5\u8ba1\u7b97\u673a\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pip download<\/code>\u6765\u4e0b\u8f7d\u6240\u9700\u7684\u6a21\u5757\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u5c06\u4e0b\u8f7d\u7684\u6587\u4ef6\u8f6c\u79fb\u5230\u65e0\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>pip install &lt;file_name&gt;<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u679c\u67d0\u4e2a\u6a21\u5757\u6709\u4f9d\u8d56\u5173\u7cfb\uff0c\u5982\u4f55\u5728\u79bb\u7ebf\u73af\u5883\u4e2d\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u4e0b\u8f7d\u6a21\u5757\u65f6\uff0c\u786e\u4fdd\u4f7f\u7528<code>pip download &lt;module_name&gt;<\/code>\uff0c\u8fd9\u5c06\u81ea\u52a8\u4e0b\u8f7d\u8be5\u6a21\u5757\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u9879\u3002\u60a8\u53ef\u4ee5\u5c06\u6240\u6709\u4e0b\u8f7d\u7684\u6587\u4ef6\u4fdd\u5b58\u5728\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u8f6c\u79fb\u5230\u65e0\u7f51\u7edc\u7684\u73af\u5883\u4e2d\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install --no-index --find-links=&lt;directory&gt; &lt;module_name&gt;<\/code>\u6765\u5b89\u88c5\u6a21\u5757\u53ca\u5176\u4f9d\u8d56\u5173\u7cfb\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u56e0\u7f3a\u5c11\u4f9d\u8d56\u800c\u5bfc\u81f4\u5b89\u88c5\u5931\u8d25\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5Python\u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u79bb\u7ebf\u5b89\u88c5\u5305\u3001\u62f7\u8d1d\u5df2\u6709\u73af\u5883\u3001\u4f7f\u7528\u672c\u5730\u955c\u50cf\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1183001,"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\/1182993"}],"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=1182993"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182993\/revisions"}],"predecessor-version":[{"id":1183004,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182993\/revisions\/1183004"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1183001"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1182993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1182993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1182993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}