{"id":1086426,"date":"2025-01-08T13:25:30","date_gmt":"2025-01-08T05:25:30","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1086426.html"},"modified":"2025-01-08T13:25:33","modified_gmt":"2025-01-08T05:25:33","slug":"python%e8%87%aa%e5%b8%a6pip%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1086426.html","title":{"rendered":"python\u81ea\u5e26pip\u5982\u4f55\u6dfb\u52a0\u73af\u5883\u53d8\u91cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195837\/8c4243eb-ba3c-4988-8bda-76202d2ee27c.webp\" alt=\"python\u81ea\u5e26pip\u5982\u4f55\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\" \/><\/p>\n<p><p> <strong>Python\u81ea\u5e26pip\u5982\u4f55\u6dfb\u52a0\u73af\u5883\u53d8\u91cf<\/strong>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff1a<strong>\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u4e34\u65f6\u6dfb\u52a0\u3001\u901a\u8fc7Python\u811a\u672c\u6dfb\u52a0<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u4e14\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u786e\u4fdd\u5728\u6240\u6709\u547d\u4ee4\u884c\u4f1a\u8bdd\u4e2d\uff0cPython\u548cpip\u90fd\u53ef\u4ee5\u88ab\u6b63\u786e\u8bc6\u522b\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u8981\u8be6\u7ec6\u5c55\u5f00<strong>\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf<\/strong>\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><h4>1. Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u7cfb\u7edf\u5c5e\u6027<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e<\/strong>\uff1a\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u8f91\u7cfb\u7edf\u53d8\u91cf<\/strong>\uff1a\u5728\u201c\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u627e\u5230\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u9009\u62e9\u201cPath\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0Python\u548cpip\u8def\u5f84<\/strong>\uff1a\u5728\u201c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u548cScripts\u76ee\u5f55\u8def\u5f84\u5206\u522b\u6dfb\u52a0\u8fdb\u53bb\u3002\u4f8b\u5982\uff0c\u5982\u679cPython\u5b89\u88c5\u5728C:\\Python39\uff0c\u5219\u6dfb\u52a0\u7684\u8def\u5f84\u53ef\u80fd\u662f\uff1a<\/p>\n<\/p>\n<p><pre><code>C:\\Python39<\/p>\n<p>C:\\Python39\\Scripts<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u4fee\u6539<\/strong>\uff1a\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u4fee\u6539\uff0c\u5173\u95ed\u6240\u6709\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>2. macOS\u548cLinux\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u4fee\u6539\u73af\u5883\u53d8\u91cf\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u7ec8\u7aef<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u8f91shell\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00shell\u914d\u7f6e\u6587\u4ef6\uff08\u4f8b\u5982\uff0c.bashrc\u3001.bash_profile\u3001.zshrc\u7b49\uff09\u3002\u5177\u4f53\u6587\u4ef6\u53d6\u51b3\u4e8e\u4f60\u4f7f\u7528\u7684shell\u7c7b\u578b\u3002\u4ee5\u7f16\u8f91.bashrc\u6587\u4ef6\u4e3a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">nano ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0Python\u548cpip\u8def\u5f84<\/strong>\uff1a\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5c06\u8def\u5f84\u66ff\u6362\u4e3a\u4f60\u7684Python\u5b89\u88c5\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">export PATH=&quot;\/usr\/local\/bin\/python3.9:$PATH&quot;<\/p>\n<p>export PATH=&quot;\/usr\/local\/bin\/python3.9\/Scripts:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u4fee\u6539\u5e76\u5237\u65b0\u914d\u7f6e<\/strong>\uff1a\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u7f16\u8f91\u5668\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u4f7f\u4fee\u6539\u751f\u6548\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u4e34\u65f6\u6dfb\u52a0<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u53ea\u60f3\u4e34\u65f6\u6dfb\u52a0Python\u548cpip\u8def\u5f84\uff0c\u800c\u4e0d\u5e0c\u671b\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3002\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u6216PowerShell\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">set PATH=C:\\Python39;C:\\Python39\\Scripts;%PATH%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. macOS\u548cLinux\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u6253\u5f00\u7ec8\u7aef\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">export PATH=&quot;\/usr\/local\/bin\/python3.9:\/usr\/local\/bin\/python3.9\/Scripts:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u901a\u8fc7Python\u811a\u672c\u6dfb\u52a0<\/h3>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7Python\u811a\u672c\u52a8\u6001\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import sys<\/p>\n<h2><strong>\u5b9a\u4e49Python\u548cpip\u8def\u5f84<\/strong><\/h2>\n<p>python_path = &quot;\/usr\/local\/bin\/python3.9&quot;<\/p>\n<p>scripts_path = &quot;\/usr\/local\/bin\/python3.9\/Scripts&quot;<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p>current_path = os.environ.get(&quot;PATH&quot;, &quot;&quot;)<\/p>\n<h2><strong>\u66f4\u65b0\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p>new_path = f&quot;{python_path}:{scripts_path}:{current_path}&quot;<\/p>\n<p>os.environ[&quot;PATH&quot;] = new_path<\/p>\n<h2><strong>\u9a8c\u8bc1\u4fee\u6539<\/strong><\/h2>\n<p>print(f&quot;Updated PATH: {os.environ[&#39;PATH&#39;]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u6b64\u811a\u672c\u540e\uff0c\u53ef\u4ee5\u5728\u540c\u4e00\u4f1a\u8bdd\u4e2d\u4f7f\u7528\u66f4\u65b0\u540e\u7684\u73af\u5883\u53d8\u91cf\u3002\u4f46\u662f\u8bf7\u6ce8\u610f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4ec5\u5728\u811a\u672c\u8fd0\u884c\u7684\u5f53\u524d\u4f1a\u8bdd\u4e2d\u6709\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p><strong>\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf<\/strong>\u662f\u786e\u4fddPython\u548cpip\u5728\u6240\u6709\u547d\u4ee4\u884c\u4f1a\u8bdd\u4e2d\u90fd\u80fd\u88ab\u6b63\u786e\u8bc6\u522b\u548c\u4f7f\u7528\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u3002\u901a\u8fc7\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u6dfb\u52a0Python\u548cpip\u7684\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u907f\u514d\u5728\u6bcf\u6b21\u6253\u5f00\u547d\u4ee4\u884c\u65f6\u90fd\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u8def\u5f84\u3002\u5bf9\u4e8e\u4e34\u65f6\u6027\u9700\u6c42\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u4e34\u65f6\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u7684\u65b9\u6cd5\u3002\u5982\u679c\u9700\u8981\u5728\u811a\u672c\u4e2d\u52a8\u6001\u4fee\u6539\u73af\u5883\u53d8\u91cf\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7Python\u811a\u672c\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u786e\u4fddPython\u548cpip\u7684\u8def\u5f84\u6b63\u786e\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u5347\u5f00\u53d1\u6548\u7387\u548c\u4fbf\u6377\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u6211\u7684Python\u548cpip\u662f\u5426\u5df2\u6b63\u786e\u5b89\u88c5\uff1f<\/strong><br \/>\u8981\u786e\u8ba4Python\u548cpip\u662f\u5426\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>python --version<\/code>\u548c<code>pip --version<\/code>\u3002\u5982\u679c\u8fd9\u4e24\u4e2a\u547d\u4ee4\u8fd4\u56de\u4e86\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b83\u4eec\u5df2\u6210\u529f\u5b89\u88c5\u3002\u82e5\u672a\u8fd4\u56de\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u91cd\u65b0\u5b89\u88c5Python\uff0c\u5e76\u786e\u4fdd\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9009\u62e9\u4e86\u201c\u5c06Python\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u201d\u9009\u9879\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Windows\u7cfb\u7edf\u4e2d\u624b\u52a8\u6dfb\u52a0pip\u5230\u73af\u5883\u53d8\u91cf\uff1f<\/strong><br \/>\u5982\u679c\u5728\u5b89\u88c5Python\u65f6\u6ca1\u6709\u9009\u62e9\u81ea\u52a8\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\uff0c\u60a8\u53ef\u4ee5\u624b\u52a8\u8fdb\u884c\u8bbe\u7f6e\u3002\u53f3\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002\u5728\u7cfb\u7edf\u5c5e\u6027\u7a97\u53e3\u4e2d\uff0c\u9009\u62e9\u201c\u73af\u5883\u53d8\u91cf\u201d\uff0c\u5728\u7cfb\u7edf\u53d8\u91cf\u4e2d\u627e\u5230\u201cPath\u201d\uff0c\u70b9\u51fb\u7f16\u8f91\uff0c\u6dfb\u52a0pip\u7684\u5b89\u88c5\u8def\u5f84\uff08\u901a\u5e38\u4e3a<code>C:\\PythonXX\\Scripts<\/code>\uff0cXX\u4e3aPython\u7248\u672c\u53f7\uff09\u5e76\u4fdd\u5b58\u66f4\u6539\u3002<\/p>\n<p><strong>\u6211\u8be5\u5982\u4f55\u5728Linux\u6216Mac\u7cfb\u7edf\u4e2d\u8bbe\u7f6epip\u73af\u5883\u53d8\u91cf\uff1f<\/strong><br \/>\u5728Linux\u6216Mac\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\u6765\u6dfb\u52a0pip\u7684\u8def\u5f84\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>nano ~\/.bashrc<\/code>\u6216<code>nano ~\/.bash_profile<\/code>\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<code>export PATH=&quot;$PATH:\/usr\/local\/bin&quot;<\/code>\uff08\u8bf7\u6839\u636e\u60a8\u7684\u5b9e\u9645pip\u5b89\u88c5\u8def\u5f84\u8fdb\u884c\u8c03\u6574\uff09\u3002\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u8fd0\u884c<code>source ~\/.bashrc<\/code>\u6216<code>source ~\/.bash_profile<\/code>\u4ee5\u5e94\u7528\u66f4\u6539\u3002\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528pip\u547d\u4ee4\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u81ea\u5e26pip\u5982\u4f55\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff1a\u4fee\u6539\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u4e34\u65f6\u6dfb\u52a0\u3001\u901a\u8fc7Py [&hellip;]","protected":false},"author":3,"featured_media":1086429,"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\/1086426"}],"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=1086426"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1086426\/revisions"}],"predecessor-version":[{"id":1086430,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1086426\/revisions\/1086430"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1086429"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1086426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1086426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1086426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}