{"id":176771,"date":"2024-05-08T19:17:37","date_gmt":"2024-05-08T11:17:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/176771.html"},"modified":"2024-05-08T19:17:45","modified_gmt":"2024-05-08T11:17:45","slug":"%e5%90%8c%e6%97%b6%e8%a3%85%e4%ba%86python3%e5%92%8cpython2%ef%bc%8c%e6%80%8e%e4%b9%88%e7%94%a8pip","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/176771.html","title":{"rendered":"\u540c\u65f6\u88c5\u4e86Python3\u548cPython2\uff0c\u600e\u4e48\u7528pip"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27060541\/180429ca-495e-462b-9784-36b2320410cd.webp\" alt=\"\u540c\u65f6\u88c5\u4e86Python3\u548cPython2\uff0c\u600e\u4e48\u7528pip\" \/><\/p>\n<p><p>\u5f53\u60a8\u7684\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b89\u88c5\u4e86Python3\u548cPython2\u65f6\uff0c\u4f7f\u7528\u5408\u9002\u7684pip\u7248\u672c\u6765\u7ba1\u7406\u5404\u81ea\u73af\u5883\u4e2d\u7684\u5305\u53d8\u5f97\u5c24\u4e3a\u91cd\u8981\u3002<strong>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0cPython2\u548cPython3\u4f1a\u5404\u81ea\u5b89\u88c5\u5bf9\u5e94\u7684pip\u7248\u672c\u2014pip2\u548cpip3<\/strong>\u3001\u8fd9\u662f\u56e0\u4e3a\u4e24\u4e2aPython\u7248\u672c\u5177\u6709\u4e0d\u517c\u5bb9\u7684\u5e93\uff0c\u56e0\u800c\u9700\u8981\u72ec\u7acb\u7ba1\u7406\u3002\u5728\u8fd9\u91cc\uff0c<strong>\u6700\u6838\u5fc3\u7684\u64cd\u4f5c\u662f\u533a\u5206pip\u547d\u4ee4<\/strong>\uff0c\u786e\u4fdd\u60a8\u4e3a\u6240\u9700\u7684Python\u7248\u672c\u5b89\u88c5\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u8981\u8be6\u7ec6\u63cf\u8ff0\u7684\u662f\uff1a\u4e3a\u4e86\u907f\u514d\u51b2\u7a81\u548c\u786e\u4fdd\u73af\u5883\u7684\u6e05\u6670\uff0c\u901a\u5e38\u63a8\u8350\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002Python3.3\u53ca\u4ee5\u4e0a\u7248\u672c\u5185\u7f6e\u4e86<code>venv<\/code>\u6a21\u5757\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u8fd9\u53ef\u4ee5\u8ba9\u60a8\u5728\u9879\u76ee\u57fa\u7840\u4e0a\u7ef4\u6301\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u5305\u62ec\u4f7f\u7528\u7279\u5b9a\u7248\u672c\u7684pip\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5230\u5168\u5c40\u73af\u5883\u3002\u8fd9\u79cd\u505a\u6cd5\u5c24\u4e3a\u6709\u76ca\u4e8e\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u9879\u76ee\uff0c\u6bcf\u4e2a\u9879\u76ee\u90fd\u53ef\u80fd\u4f9d\u8d56\u4e8e\u4e0d\u540c\u7248\u672c\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u68c0\u67e5PIP\u7248\u672c<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u8ba4\u5b89\u88c5\u4e86pip\u4e14\u77e5\u6653\u5982\u4f55\u8c03\u7528\u5408\u9002\u7248\u672c\u7684pip\u975e\u5e38\u5173\u952e\u3002\u5728\u547d\u4ee4\u884c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip --version<\/p>\n<p>pip2 --version<\/p>\n<p>pip3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u663e\u793apip\u7684\u7248\u672c\u4ee5\u53ca\u5b83\u662f\u5173\u8054\u5230Python2\u8fd8\u662fPython3\u3002\u4e86\u89e3\u4e86\u8fd9\u4e2a\u4fe1\u606f\uff0c\u60a8\u4fbf\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u7528\u6b63\u786e\u7684pip\u7248\u672c\u6765\u5b89\u88c5\u3001\u66f4\u65b0\u6216\u5220\u9664\u5305\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528PIP3\u4e3aPython3\u5b89\u88c5\u5305<\/h3>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u4e3aPython3\u5b89\u88c5\u5305\u65f6\uff0c\u60a8\u5e94\u8be5\u4f7f\u7528pip3\u3002\u64cd\u4f5c\u65b9\u6cd5\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\uff0c<code>package_name<\/code>\u662f\u60a8\u60f3\u8981\u5b89\u88c5\u7684\u5305\u7684\u540d\u79f0\u3002\u4f7f\u7528pip3\uff0c\u786e\u4fdd\u4e86\u8be5\u5305\u53ca\u5176\u4f9d\u8d56\u90fd\u4f1a\u88ab\u5b89\u88c5\u5728Python3\u7684\u73af\u5883\u4e0b\uff0c\u800c\u4e0d\u4f1a\u5bf9Python2\u7684\u73af\u5883\u9020\u6210\u5e72\u6270\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528PIP2\u4e3aPython2\u5b89\u88c5\u5305<\/h3>\n<\/p>\n<p><p>\u540c\u6837\u5730\uff0c\u5f53\u9700\u8981\u4e3aPython2\u5b89\u88c5\u5305\u65f6\uff0c\u60a8\u5e94\u4f7f\u7528pip2\u3002\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip2 install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4fdd\u8bc1\u4e86\u5305\u4ec5\u5b89\u88c5\u5728Python2\u7684\u73af\u5883\u4e2d\u3002\u867d\u7136Python2\u57282020\u5e74\u521d\u5df2\u7ecf\u505c\u6b62\u4e86\u5b98\u65b9\u652f\u6301\uff0c\u4f46\u4ecd\u7136\u6709\u8bb8\u591a\u9057\u7559\u9879\u76ee\u4f9d\u8d56\u4e8e\u5b83\uff0c\u56e0\u6b64\u6b63\u786e\u5730\u7ba1\u7406\u5176\u4f9d\u8d56\u4ecd\u7136\u5f88\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u9488\u5bf9\u4e0d\u540c\u7684\u9879\u76ee\u4f7f\u7528\u4e0d\u540c\u7684Python\u73af\u5883\u662f\u4e00\u79cd\u597d\u4e60\u60ef\u3002Python3\u7684<code>venv<\/code>\u6a21\u5757\u8ba9\u8fd9\u4e00\u70b9\u53d8\u5f97\u5c24\u4e3a\u7b80\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728<code>myenv<\/code>\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u6fc0\u6d3b\u540e\uff0c\u60a8\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u4f7f\u7528pip\u5b89\u88c5\u7684\u6240\u6709\u5305\u90fd\u5c06\u548c\u7cfb\u7edf\u7684\u5168\u5c40\u73af\u5883\u9694\u79bb\u5f00\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5982\u4f55\u5207\u6362PIP\u7248\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5207\u6362\u9ed8\u8ba4\u7684pip\u7248\u672c\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u6216\u4f7f\u7528\u522b\u540d\u6765\u5b9e\u73b0\u3002\u5728bash\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4e3apip3\u8bbe\u7f6e\u522b\u540d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">alias pip=pip3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u4e00\u6765\uff0c\u5f53\u60a8\u8f93\u5165<code>pip install package_name<\/code>\u65f6\uff0c\u5b9e\u9645\u4e0a\u4f1a\u8c03\u7528<code>pip3<\/code>\u6765\u5b89\u88c5\u5305\u3002<\/p>\n<\/p>\n<p><p><strong>\u603b\u4e4b\uff0c\u5408\u7406\u4f7f\u7528pip2\u548cpip3\uff0c\u4ee5\u53ca\u5145\u5206\u5229\u7528\u865a\u62df\u73af\u5883\uff0c\u5bf9\u4e8e\u5728\u4e00\u4e2a\u7cfb\u7edf\u4e0a\u7ba1\u7406\u540c\u65f6\u5b58\u5728\u7684Python2\u548cPython3\u73af\u5883\u81f3\u5173\u91cd\u8981\u3002<\/strong> \u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u5e93\u548c\u9879\u76ee\u7684\u4f9d\u8d56\u6b63\u786e\u5730\u88ab\u7ba1\u7406\u548c\u9694\u79bb\uff0c\u4ece\u800c\u907f\u514d\u6f5c\u5728\u7684\u7248\u672c\u51b2\u7a81\u5e76\u4fdd\u6301\u5f00\u53d1\u73af\u5883\u7684\u6574\u6d01\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728\u540c\u65f6\u5b89\u88c5Python3\u548cPython2\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528pip\uff1f<\/strong><\/p>\n<p>\u5728\u540c\u65f6\u5b89\u88c5Python3\u548cPython2\u7684\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u907f\u514d\u6df7\u6dc6\uff0c\u6211\u4eec\u9700\u8981\u660e\u786e\u4f7f\u7528\u54ea\u4e2a\u7248\u672c\u7684pip\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Python3\u7684pip3\u6765\u5b89\u88c5Python3\u9700\u8981\u7684\u5305\uff0c\u4f7f\u7528Python2\u7684pip\u6765\u5b89\u88c5Python2\u9700\u8981\u7684\u5305\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u4f7f\u7528Python3\u7684pip\u5b89\u88c5\u5305\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip3 install package_name<\/code>\u6765\u5b89\u88c5\u7279\u5b9a\u7684\u5305\u3002\u7c7b\u4f3c\u5730\uff0c\u8981\u4f7f\u7528Python2\u7684pip\u5b89\u88c5\u5305\uff0c\u53ef\u4ee5\u8f93\u5165<code>pip install package_name<\/code>\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5728\u540c\u65f6\u5b89\u88c5Python3\u548cPython2\u7684\u60c5\u51b5\u4e0b\u786e\u4fdd\u6b63\u786e\u5b89\u88c5\u5305\uff1f<\/strong><\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u5b89\u88c5\u7684\u5305\u4e0e\u4f60\u60f3\u8981\u7684Python\u7248\u672c\u517c\u5bb9\uff0c\u53ef\u4ee5\u5728\u5b89\u88c5\u5305\u65f6\u4f7f\u7528\u7279\u5b9a\u7248\u672c\u7684pip\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Python3\u7684pip3\u6765\u5b89\u88c5Python3\u9700\u8981\u7684\u5305\uff0c\u4f7f\u7528Python2\u7684pip\u6765\u5b89\u88c5Python2\u9700\u8981\u7684\u5305\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u9694\u79bb\u4e0d\u540c\u7248\u672c\u7684Python\u548c\u76f8\u5e94\u7684\u5305\u3002\u865a\u62df\u73af\u5883\u5141\u8bb8\u4f60\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u548c\u5305\uff0c\u4ee5\u907f\u514d\u7248\u672c\u51b2\u7a81\u548c\u6df7\u4e71\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u5728\u540c\u65f6\u5b89\u88c5Python3\u548cPython2\u7684\u60c5\u51b5\u4e0b\u5378\u8f7d\u5305\uff1f<\/strong><\/p>\n<p>\u5728\u5378\u8f7d\u5305\u65f6\uff0c\u540c\u6837\u9700\u8981\u4f7f\u7528\u6b63\u786e\u7684pip\u7248\u672c\u3002\u5982\u679c\u4f60\u60f3\u5378\u8f7dPython3\u4e0b\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528pip3\u6765\u5378\u8f7d\u3002\u7c7b\u4f3c\u5730\uff0c\u5982\u679c\u60f3\u5378\u8f7dPython2\u4e0b\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5378\u8f7d\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5728Python3\u4e0b\u5378\u8f7d\u7279\u5b9a\u7684\u5305\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip3 uninstall package_name<\/code>\u3002\u540c\u6837\uff0c\u8981\u5728Python2\u4e0b\u5378\u8f7d\u5305\uff0c\u53ef\u4ee5\u8f93\u5165<code>pip uninstall package_name<\/code>\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684pip\u7248\u672c\u6765\u5378\u8f7d\u5305\uff0c\u4ee5\u907f\u514d\u9519\u8bef\u5730\u5220\u9664\u4e0d\u7b26\u5408\u76ee\u6807Python\u7248\u672c\u7684\u5305\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f53\u60a8\u7684\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b89\u88c5\u4e86Python3\u548cPython2\u65f6\uff0c\u4f7f\u7528\u5408\u9002\u7684pip\u7248\u672c\u6765\u7ba1\u7406\u5404\u81ea\u73af\u5883\u4e2d\u7684\u5305\u53d8\u5f97\u5c24\u4e3a\u91cd\u8981\u3002 [&hellip;]","protected":false},"author":3,"featured_media":176789,"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\/176771"}],"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=176771"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/176771\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/176789"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=176771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=176771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=176771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}