{"id":947773,"date":"2024-12-26T23:54:50","date_gmt":"2024-12-26T15:54:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/947773.html"},"modified":"2024-12-26T23:54:53","modified_gmt":"2024-12-26T15:54:53","slug":"python%e5%a6%82%e4%bd%95%e9%87%8d%e8%a3%85%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/947773.html","title":{"rendered":"python\u5982\u4f55\u91cd\u88c5\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083417\/0dd359bb-01f8-4a41-ba63-89082ce3a704.webp\" alt=\"python\u5982\u4f55\u91cd\u88c5\u5305\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/><strong>Python\u91cd\u88c5\u5305\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528pip\u5378\u8f7d\u540e\u91cd\u65b0\u5b89\u88c5\u3001\u4f7f\u7528conda\u8fdb\u884c\u7ba1\u7406\u3001\u5347\u7ea7\u6216\u964d\u7ea7\u5305\u7248\u672c<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528pip\u5de5\u5177\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3apip\u662fPython\u9ed8\u8ba4\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u652f\u6301\u5927\u591a\u6570Python\u73af\u5883\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u6267\u884c<code>pip uninstall package_name<\/code>\u53ef\u4ee5\u5378\u8f7d\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u7136\u540e\u518d\u901a\u8fc7<code>pip install package_name<\/code>\u91cd\u65b0\u5b89\u88c5\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u5408\u4e8e\u9700\u8981\u6e05\u7406\u5305\u4f9d\u8d56\u5173\u7cfb\u6216\u89e3\u51b3\u5305\u51b2\u7a81\u7684\u573a\u666f\u3002\u6b64\u5916\uff0cconda\u73af\u5883\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5305\u7ba1\u7406\uff0c\u7279\u522b\u662f\u5728\u4f7f\u7528Anaconda\u53d1\u884c\u7248\u65f6\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e3a\u5f3a\u5927\u7684\u4f9d\u8d56\u7ba1\u7406\u529f\u80fd\u3002\u5347\u7ea7\u6216\u964d\u7ea7\u7279\u5b9a\u7248\u672c\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u89e3\u51b3\u517c\u5bb9\u6027\u95ee\u9898\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5de5\u5177\u5378\u8f7d\u548c\u91cd\u65b0\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cpip\u662f\u6700\u5e38\u7528\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u5730\u5b89\u88c5\u3001\u5347\u7ea7\u548c\u5378\u8f7dPython\u5305\u3002\u8981\u91cd\u88c5\u4e00\u4e2aPython\u5305\uff0c\u9996\u5148\u9700\u8981\u5c06\u5176\u5378\u8f7d\uff0c\u7136\u540e\u518d\u91cd\u65b0\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5378\u8f7dPython\u5305<\/strong><br \/>\u5378\u8f7d\u4e00\u4e2aPython\u5305\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip uninstall package_name<\/code>\u6765\u5b9e\u73b0\u3002\u5728\u6267\u884c\u8be5\u547d\u4ee4\u65f6\uff0cpip\u4f1a\u8be2\u95ee\u786e\u8ba4\u4fe1\u606f\uff0c\u8981\u6c42\u786e\u8ba4\u662f\u5426\u8981\u5378\u8f7d\u8be5\u5305\u3002\u5b8c\u6210\u786e\u8ba4\u540e\uff0cpip\u5c06\u5220\u9664\u5305\u6587\u4ef6\u53ca\u5176\u6240\u6709\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u91cd\u65b0\u5b89\u88c5Python\u5305<\/strong><br \/>\u4e00\u65e6\u5305\u88ab\u5378\u8f7d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install package_name<\/code>\u6765\u91cd\u65b0\u5b89\u88c5\u3002\u5728\u91cd\u65b0\u5b89\u88c5\u65f6\uff0cpip\u4f1a\u4ecePython Package Index (PyPI)\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684\u5305\u3002\u6b64\u65b9\u6cd5\u786e\u4fdd\u4e86\u5305\u7684\u6700\u65b0\u7248\u672c\u548c\u4f9d\u8d56\u5173\u7cfb\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528CONDA\u8fdb\u884c\u5305\u7ba1\u7406<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4f7f\u7528Anaconda\u6216Miniconda\u7684\u7528\u6237\uff0cconda\u662f\u53e6\u4e00\u79cd\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002Conda\u4e0d\u4ec5\u53ef\u4ee5\u7ba1\u7406Python\u5305\uff0c\u8fd8\u53ef\u4ee5\u7ba1\u7406\u5176\u4ed6\u4e8c\u8fdb\u5236\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Conda\u5378\u8f7d\u5305<\/strong><br \/>\u8981\u4f7f\u7528conda\u5378\u8f7d\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>conda remove package_name<\/code>\u3002\u4e0epip\u7c7b\u4f3c\uff0cconda\u4e5f\u4f1a\u5220\u9664\u5305\u53ca\u5176\u76f8\u5173\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Conda\u91cd\u65b0\u5b89\u88c5\u5305<\/strong><br \/>\u4f7f\u7528\u547d\u4ee4<code>conda install package_name<\/code>\u53ef\u4ee5\u91cd\u65b0\u5b89\u88c5\u5305\u3002Conda\u4f1a\u4eceAnaconda\u4ed3\u5e93\u4e2d\u83b7\u53d6\u5305\uff0c\u5e76\u786e\u4fdd\u5176\u4e0e\u5f53\u524d\u73af\u5883\u7684\u4f9d\u8d56\u5173\u7cfb\u517c\u5bb9\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5347\u7ea7\u6216\u964d\u7ea7\u5305\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u4e0d\u9700\u8981\u5b8c\u5168\u91cd\u88c5\u5305\uff0c\u800c\u53ea\u9700\u5347\u7ea7\u6216\u964d\u7ea7\u5230\u7279\u5b9a\u7248\u672c\u5373\u53ef\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5347\u7ea7\u5305<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pip install --upgrade package_name<\/code>\u547d\u4ee4\u6765\u5347\u7ea7\u5305\u5230\u6700\u65b0\u7248\u672c\u3002\u6b64\u547d\u4ee4\u4f1a\u81ea\u52a8\u68c0\u67e5\u5e76\u66f4\u65b0\u5305\u5230PyPI\u4e0a\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u964d\u7ea7\u5305<\/strong><br \/>\u5982\u679c\u65b0\u7248\u672c\u7684\u5305\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u7248\u672c\u53f7\u6765\u964d\u7ea7\u5305\uff0c\u4f8b\u5982<code>pip install package_name==1.0.0<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u89e3\u51b3\u5305\u4f9d\u8d56\u51b2\u7a81<\/p>\n<\/p>\n<p><p>\u5728\u91cd\u88c5\u5305\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5305\u4f9d\u8d56\u51b2\u7a81\u7684\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong><br \/>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u9879\u76ee\u53d1\u751f\u51b2\u7a81\u3002\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u4f8b\u5982<code>python -m venv myenv<\/code>\uff0c\u7136\u540e\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u8fdb\u884c\u5305\u7ba1\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u4f9d\u8d56\u5173\u7cfb<\/strong><br \/>\u4f7f\u7528<code>pip show package_name<\/code>\u53ef\u4ee5\u67e5\u770b\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u4ee5\u4fbf\u8bc6\u522b\u53ef\u80fd\u7684\u51b2\u7a81\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u7684\u9ad8\u7ea7\u529f\u80fd<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406Python\u5305\uff0cpip\u548cconda\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ad8\u7ea7\u529f\u80fd\uff0c\u5e2e\u52a9\u7528\u6237\u66f4\u6709\u6548\u5730\u7ba1\u7406\u548c\u89e3\u51b3\u5305\u76f8\u5173\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6<\/strong><br \/>\u5728\u9879\u76ee\u4e2d\u7ef4\u62a4\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u5217\u51fa\u6240\u6709\u9700\u8981\u7684\u5305\u53ca\u5176\u7248\u672c\u53f7\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip install -r requirements.txt<\/code>\u547d\u4ee4\u5b89\u88c5\u6240\u6709\u5305\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u91cd\u73b0\u76f8\u540c\u7684\u73af\u5883\u914d\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u9501\u5b9a\u6587\u4ef6<\/strong><br \/>\u4f7f\u7528\u5de5\u5177\u5982<code>pipenv<\/code>\u6216<code>poetry<\/code>\uff0c\u53ef\u4ee5\u751f\u6210\u9501\u5b9a\u6587\u4ef6\uff0c\u8bb0\u5f55\u7cbe\u786e\u7684\u5305\u7248\u672c\u4fe1\u606f\u3002\u8fd9\u5bf9\u4e8e\u4fdd\u8bc1\u73af\u5883\u4e00\u81f4\u6027\u548c\u4f9d\u8d56\u7ba1\u7406\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u91cd\u88c5Python\u5305\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u65e0\u8bba\u662f\u4e3a\u4e86\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u8fd8\u662f\u89e3\u51b3\u4f9d\u8d56\u51b2\u7a81\u3002\u901a\u8fc7\u719f\u7ec3\u4f7f\u7528pip\u6216conda\u7b49\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u7ef4\u62a4Python\u5f00\u53d1\u73af\u5883\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u5378\u8f7d\u548c\u91cd\u65b0\u5b89\u88c5\uff0c\u8fd8\u662f\u901a\u8fc7\u5347\u7ea7\u6216\u964d\u7ea7\u7248\u672c\uff0c\u9009\u62e9\u9002\u5408\u81ea\u5df1\u9879\u76ee\u9700\u6c42\u7684\u65b9\u6cd5\u81f3\u5173\u91cd\u8981\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u548c\u9501\u5b9a\u6587\u4ef6\u7b49\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u63a7\u5236\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u786e\u4fdd\u5f00\u53d1\u8fc7\u7a0b\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9884\u6d4b\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u5305\u7248\u672c\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip list<\/code>\u6765\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u6240\u6709Python\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u60a8\u53ea\u60f3\u67e5\u770b\u7279\u5b9a\u5305\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip show \u5305\u540d<\/code>\uff0c\u8fd9\u6837\u53ef\u4ee5\u83b7\u5f97\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u3001\u4f9d\u8d56\u5173\u7cfb\u548c\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<p><strong>\u91cd\u88c5Python\u5305\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u91cd\u88c5\u5305\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u4e86\u89e3\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u548c\u4f7f\u7528\u60c5\u51b5\u3002\u67d0\u4e9b\u5305\u53ef\u80fd\u4e0e\u5176\u4ed6\u5305\u6709\u4f9d\u8d56\u5173\u7cfb\uff0c\u91cd\u88c5\u65f6\u53ef\u80fd\u4f1a\u5f71\u54cd\u5230\u5176\u4ed6\u5305\u7684\u529f\u80fd\u3002\u5efa\u8bae\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fdb\u884c\u5305\u7684\u7ba1\u7406\uff0c\u4ee5\u907f\u514d\u5bf9\u5168\u5c40\u73af\u5883\u9020\u6210\u5e72\u6270\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u6307\u5b9a\u7248\u672c\u91cd\u88c5\u5305\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728pip\u547d\u4ee4\u4e2d\u6307\u5b9a\u7248\u672c\u53f7\u6765\u91cd\u88c5\u7279\u5b9a\u7248\u672c\u7684\u5305\uff0c\u4f8b\u5982\u4f7f\u7528<code>pip install \u5305\u540d==\u7248\u672c\u53f7<\/code>\u3002\u8fd9\u79cd\u65b9\u5f0f\u80fd\u591f\u5e2e\u52a9\u60a8\u786e\u4fdd\u4f7f\u7528\u7279\u5b9a\u7248\u672c\u7684\u5305\uff0c\u907f\u514d\u56e0\u7248\u672c\u4e0d\u517c\u5bb9\u800c\u5bfc\u81f4\u7684\u95ee\u9898\u3002\u5728\u91cd\u88c5\u4e4b\u524d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip uninstall \u5305\u540d<\/code>\u547d\u4ee4\u5148\u5378\u8f7d\u5f53\u524d\u7248\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1aPython\u91cd\u88c5\u5305\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528pip\u5378\u8f7d\u540e\u91cd\u65b0\u5b89\u88c5\u3001\u4f7f\u7528conda\u8fdb\u884c\u7ba1\u7406\u3001\u5347\u7ea7\u6216\u964d\u7ea7\u5305\u7248\u672c\u3002\u5176\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":947774,"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\/947773"}],"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=947773"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/947773\/revisions"}],"predecessor-version":[{"id":947775,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/947773\/revisions\/947775"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/947774"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=947773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=947773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=947773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}