{"id":951196,"date":"2024-12-27T00:53:52","date_gmt":"2024-12-26T16:53:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/951196.html"},"modified":"2024-12-27T00:53:54","modified_gmt":"2024-12-26T16:53:54","slug":"pip%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/951196.html","title":{"rendered":"pip\u5982\u4f55\u5b89\u88c5python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085457\/185a55af-b6dc-4e80-8103-c00b15d0dcac.webp\" alt=\"pip\u5982\u4f55\u5b89\u88c5python\" \/><\/p>\n<p><p> <strong>\u8981\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Python\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u7684\u5b89\u88c5\u7a0b\u5e8f\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5982Homebrew\uff08macOS\uff09\u6216apt\uff08Linux\uff09\uff0c\u6216\u8005\u4f7f\u7528Windows\u7684Microsoft Store\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u6bcf\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u5b89\u88c5Python\u7684\u6307\u5bfc\u6b65\u9aa4\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>pip<\/code>\u6765\u7ba1\u7406Python\u5305\u3002\u8fd9\u4e9b\u65b9\u6cd5\u7684\u9009\u62e9\u5c06\u53d6\u51b3\u4e8e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c\u4e2a\u4eba\u504f\u597d\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u901a\u8fc7\u5b98\u65b9\u7f51\u7ad9\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>Python\u7684\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u4e86\u9002\u7528\u4e8eWindows\u3001macOS\u548cLinux\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u8fd9\u662f\u5b89\u88c5Python\u7684\u6700\u76f4\u63a5\u548c\u53ef\u9760\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\u5b89\u88c5\u7a0b\u5e8f<\/strong><br \/>\u9996\u5148\uff0c\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%EF%BC%8C%E5%AF%BC%E8%88%AA%E5%88%B0%E2%80%9CDownloads%E2%80%9D%E9%A1%B5%E9%9D%A2%E3%80%82%E6%A0%B9%E6%8D%AE%E6%82%A8%E7%9A%84%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E9%80%89%E6%8B%A9%E7%9B%B8%E5%BA%94%E7%9A%84Python%E7%89%88%E6%9C%AC%E4%B8%8B%E8%BD%BD%E3%80%82%E5%A4%A7%E5%A4%9A%E6%95%B0%E7%94%A8%E6%88%B7%E4%BC%9A%E9%80%89%E6%8B%A9%E6%9C%80%E6%96%B0%E7%9A%84%E7%A8%B3%E5%AE%9A%E7%89%88%E6%9C%AC%E3%80%82\">https:\/\/www.python.org\/\uff09\uff0c\u5bfc\u822a\u5230\u201cDownloads\u201d\u9875\u9762\u3002\u6839\u636e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u76f8\u5e94\u7684Python\u7248\u672c\u4e0b\u8f7d\u3002\u5927\u591a\u6570\u7528\u6237\u4f1a\u9009\u62e9\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u3002<\/a><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong><br \/>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u7a0b\u5e8f\u4ee5\u542f\u52a8\u5b89\u88c5\u5411\u5bfc\u3002\u5728Windows\u4e0a\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u8f7b\u677e\u8bbf\u95eePython\u3002\u5728macOS\u548cLinux\u4e0a\uff0c\u6309\u7167\u5c4f\u5e55\u4e0a\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><br \/>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08macOS\/Linux\uff09\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u547d\u4ee4\u4ee5\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u5982\u679c\u5b89\u88c5\u6b63\u786e\uff0c\u60a8\u5c06\u770b\u5230\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4f7f\u7528macOS\u6216Linux\u7684\u7528\u6237\uff0c\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5Python\u662f\u4e00\u4e2a\u7b80\u5355\u800c\u6709\u6548\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728macOS\u4e0a\u4f7f\u7528Homebrew<\/strong><br \/>Homebrew\u662fmacOS\u4e0a\u6700\u53d7\u6b22\u8fce\u7684\u5305\u7ba1\u7406\u5668\u4e4b\u4e00\u3002\u8981\u5b89\u88c5Homebrew\uff0c\u8bf7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f7f\u7528Homebrew\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python3 --version<\/code>\u6765\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728Linux\u4e0a\u4f7f\u7528apt<\/strong><br \/>\u5bf9\u4e8e\u57fa\u4e8eDebian\u7684Linux\u53d1\u884c\u7248\uff08\u5982Ubuntu\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528apt\u5305\u7ba1\u7406\u5668\u5b89\u88c5Python\u3002\u9996\u5148\uff0c\u66f4\u65b0\u5305\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9a8c\u8bc1\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u901a\u8fc7Microsoft Store\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8eWindows\u7528\u6237\uff0cMicrosoft Store\u63d0\u4f9b\u4e86\u4e00\u79cd\u5feb\u901f\u5b89\u88c5Python\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00Microsoft Store<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u6253\u5f00Microsoft Store\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u641c\u7d22\u5e76\u5b89\u88c5Python<\/strong><br \/>\u641c\u7d22\u201cPython\u201d\uff0c\u9009\u62e9\u5b98\u65b9\u53d1\u5e03\u7684Python\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u70b9\u51fb\u201c\u83b7\u53d6\u201d\u6309\u94ae\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><br \/>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>python --version<\/code>\u4ee5\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528pip\u7ba1\u7406Python\u5305<\/p>\n<\/p>\n<p><p><code>pip<\/code>\u662fPython\u7684\u5305\u7ba1\u7406\u5668\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u5927\u591a\u6570Python\u53d1\u884c\u7248\u90fd\u81ea\u5e26<code>pip<\/code>\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pip<\/strong><br \/>\u5982\u679c\u60a8\u7684Python\u6ca1\u6709\u9644\u5e26<code>pip<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m ensurepip --default-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5347\u7ea7<code>pip<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m pip install --upgrade pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5\u5305<\/strong><br \/>\u4f8b\u5982\uff0c\u8981\u5b89\u88c5requests\u5e93\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5217\u51fa\u5df2\u5b89\u88c5\u7684\u5305<\/strong><br \/>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u6240\u6709Python\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5378\u8f7d\u5305<\/strong><br \/>\u8981\u5378\u8f7d\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip uninstall package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06<code>package_name<\/code>\u66ff\u6362\u4e3a\u60a8\u5e0c\u671b\u5378\u8f7d\u7684\u5305\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u7248\u672c<\/strong><br \/>\u5728\u5b89\u88c5Python\u65f6\uff0c\u5efa\u8bae\u9009\u62e9\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u4ee5\u83b7\u5f97\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u8bbe\u7f6e<\/strong><br \/>\u786e\u4fddPython\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5728\u7cfb\u7edf\u8def\u5f84\u4e2d\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u8f7b\u677e\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u865a\u62df\u73af\u5883<\/strong><br \/>\u4f7f\u7528Python\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u6027\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u95f4\u7684\u5305\u51b2\u7a81\u3002\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6216<code>virtualenv<\/code>\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\uff0c\u5e76\u4f7f\u7528<code>pip<\/code>\u6765\u7ba1\u7406Python\u5305\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5f00\u53d1\u8005\uff0c\u4e86\u89e3\u8fd9\u4e9b\u5b89\u88c5\u548c\u7ba1\u7406\u65b9\u6cd5\u90fd\u5c06\u6709\u52a9\u4e8e\u63d0\u9ad8\u60a8\u7684\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684\u8ba1\u7b97\u673a\u4e0a\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86pip\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86pip\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\uff08\u5728Windows\u4e0a\u662f\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\uff09\uff0c\u8f93\u5165\u547d\u4ee4 <code>pip --version<\/code> \u6216 <code>pip3 --version<\/code>\u3002\u5982\u679c\u5df2\u5b89\u88c5\uff0c\u60a8\u5c06\u770b\u5230pip\u7684\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u627e\u4e0d\u5230\u8be5\u547d\u4ee4\u3002<\/p>\n<p><strong>\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5pip\u7684\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\uff0c\u5e76\u786e\u4fdd\u5728\u5b89\u88c5\u65f6\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0cpip\u5c06\u4f1a\u81ea\u52a8\u5b89\u88c5\u3002\u5728macOS\u548cLinux\u7cfb\u7edf\u4e0a\uff0c\u60a8\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\uff0c\u4f8b\u5982\u4f7f\u7528\u547d\u4ee4 <code>sudo apt-get install python3-pip<\/code>\uff08\u9002\u7528\u4e8eUbuntu\uff09\u6216 <code>brew install python<\/code>\uff08\u9002\u7528\u4e8emacOS\uff09\u6765\u83b7\u53d6pip\u3002<\/p>\n<p><strong>\u5982\u679c\u5b89\u88c5pip\u65f6\u9047\u5230\u95ee\u9898\uff0c\u6211\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5728\u5b89\u88c5pip\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u51e0\u79cd\u89e3\u51b3\u65b9\u6848\uff1a\u786e\u4fdd\u60a8\u7684Python\u7248\u672c\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u65e0\u8bef\uff1b\u4f7f\u7528Python\u7684get-pip.py\u811a\u672c\u624b\u52a8\u5b89\u88c5pip\uff0c\u53ea\u9700\u4e0b\u8f7d\u8be5\u811a\u672c\u5e76\u5728\u7ec8\u7aef\u8fd0\u884c <code>python get-pip.py<\/code>\uff1b\u68c0\u67e5\u662f\u5426\u6709\u7f51\u7edc\u95ee\u9898\uff0c\u786e\u4fdd\u80fd\u591f\u8bbf\u95eepip\u7684\u6e90\u3002\u5982\u679c\u95ee\u9898\u4f9d\u65e7\u5b58\u5728\uff0c\u67e5\u9605pip\u7684\u5b98\u65b9\u6587\u6863\u6216\u76f8\u5173\u793e\u533a\u7684\u652f\u6301\u8bba\u575b\u53ef\u80fd\u4f1a\u63d0\u4f9b\u66f4\u591a\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Python\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u7684\u5b89\u88c5\u7a0b\u5e8f\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5982Homebr [&hellip;]","protected":false},"author":3,"featured_media":951198,"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\/951196"}],"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=951196"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/951196\/revisions"}],"predecessor-version":[{"id":951199,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/951196\/revisions\/951199"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/951198"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=951196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=951196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=951196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}