{"id":964586,"date":"2024-12-27T04:29:40","date_gmt":"2024-12-26T20:29:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/964586.html"},"modified":"2024-12-27T04:29:42","modified_gmt":"2024-12-26T20:29:42","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8pip%e5%8d%87%e7%ba%a7python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/964586.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528pip\u5347\u7ea7python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181320\/5383f3c9-1c6c-4cf8-8ea3-69b9a4900718.webp\" alt=\"\u5982\u4f55\u4f7f\u7528pip\u5347\u7ea7python\" \/><\/p>\n<p><p> <strong>\u8981\u4f7f\u7528pip\u5347\u7ea7Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3001\u4f7f\u7528pyenv\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3001\u7ed3\u5408pip\u66f4\u65b0\u76f8\u5173\u5305\u3002<\/strong>\u5176\u4e2d\uff0c\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u662f\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u8be6\u7ec6\u63cf\u8ff0\uff1a\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u662f\u5347\u7ea7Python\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u3002\u5728\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7684Python\u5b89\u88c5\u7a0b\u5e8f\uff0c\u5e76\u8fd0\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u65f6\uff0c\u786e\u4fdd\u9009\u4e2d\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u547d\u4ee4\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u80fd\u9700\u8981\u91cd\u542f\u547d\u4ee4\u884c\u7a97\u53e3\u4ee5\u52a0\u8f7d\u65b0\u7248\u672c\u7684Python\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python<\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u662f\u5927\u591a\u6570\u7528\u6237\u5347\u7ea7Python\u7684\u9996\u9009\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u90a3\u4e9b\u4e0d\u9700\u8981\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u6216\u4e0d\u719f\u6089\u547d\u4ee4\u884c\u5de5\u5177\u7684\u7528\u6237\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u524d\u5f80Python\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E5%B9%B6%E5%AF%BC%E8%88%AA%E5%88%B0%E2%80%9CDownloads%E2%80%9D%E9%A1%B5%E9%9D%A2%E3%80%82\">https:\/\/www.python.org\/\uff09\u5e76\u5bfc\u822a\u5230\u201cDownloads\u201d\u9875\u9762\u3002<\/a><\/li>\n<li>\u9009\u62e9\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u7248\u672c\uff0c\u5e76\u4e0b\u8f7d\u5b89\u88c5\u7a0b\u5e8f\u3002<\/li>\n<li>\u8fd0\u884c\u4e0b\u8f7d\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u52a1\u5fc5\u9009\u4e2d\u201cAdd Python to PATH\u201d\u9009\u9879\u3002\u8fd9\u5c06\u4f7fPython\u547d\u4ee4\u5728\u547d\u4ee4\u884c\u4e2d\u53ef\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff08Windows\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u201ccmd\u201d\uff0cMac\u548cLinux\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u201cTerminal\u201d\uff09\u3002<\/li>\n<li>\u8f93\u5165<code>python --version<\/code>\uff0c\u5982\u679c\u663e\u793a\u7684\u662f\u65b0\u7248\u672c\u7684Python\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<li>\u540c\u65f6\uff0c\u8f93\u5165<code>pip --version<\/code>\u4ee5\u786e\u4fddpip\u4e5f\u5df2\u7ecf\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528pyenv\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u5728\u540c\u4e00\u7cfb\u7edf\u4e0a\u4f7f\u7528\u591a\u4e2aPython\u7248\u672c\u7684\u5f00\u53d1\u8005\uff0cpyenv\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002\u5b83\u5141\u8bb8\u7528\u6237\u5b89\u88c5\u3001\u7ba1\u7406\u548c\u5207\u6362\u591a\u4e2aPython\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pyenv<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5bf9\u4e8eUnix\u7cfb\u7edf\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5pyenv\uff1a\n<pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5bf9\u4e8eWindows\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528Pyenv-Windows\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u65b0\u7248\u672c\u7684Python<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u547d\u4ee4<code>pyenv install &lt;version&gt;<\/code>\u6765\u5b89\u88c5\u65b0\u7248\u672c\u7684Python\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5Python 3.9\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a\n<pre><code class=\"language-bash\">pyenv install 3.9.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730Python\u7248\u672c<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528<code>pyenv global &lt;version&gt;<\/code>\u8bbe\u7f6e\u5168\u5c40Python\u7248\u672c\u3002<\/li>\n<li>\u4f7f\u7528<code>pyenv local &lt;version&gt;<\/code>\u4e3a\u5f53\u524d\u9879\u76ee\u8bbe\u7f6e\u672c\u5730Python\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u7ed3\u5408pip\u66f4\u65b0\u76f8\u5173\u5305<\/p>\n<\/p>\n<p><p>\u5728\u5347\u7ea7Python\u4e4b\u540e\uff0c\u53ef\u80fd\u9700\u8981\u66f4\u65b0\u4e0e\u4e4b\u76f8\u5173\u7684Python\u5305\u3002pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5347\u7ea7pip<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u786e\u4fddpip\u672c\u8eab\u662f\u6700\u65b0\u7684\uff1a\n<pre><code class=\"language-bash\">python -m pip install --upgrade pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u66f4\u65b0\u9879\u76ee\u4e2d\u7684\u5305<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528<code>pip list --outdated<\/code>\u67e5\u770b\u54ea\u4e9b\u5305\u9700\u8981\u66f4\u65b0\u3002<\/li>\n<li>\u4f7f\u7528<code>pip install --upgrade &lt;package_name&gt;<\/code>\u6765\u66f4\u65b0\u7279\u5b9a\u7684\u5305\u3002<\/li>\n<li>\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>pip freeze &gt; requirements.txt<\/code>\u5bfc\u51fa\u9879\u76ee\u4f9d\u8d56\uff0c\u7136\u540e\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u91cd\u65b0\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u5347\u7ea7Python\u65f6\uff0c\u9700\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u517c\u5bb9\u6027\u95ee\u9898<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u67d0\u4e9b\u65e7\u7248\u5e93\u53ef\u80fd\u4e0d\u517c\u5bb9\u65b0\u7684Python\u7248\u672c\u3002\u5728\u5347\u7ea7\u524d\uff0c\u8bf7\u786e\u4fdd\u6240\u6709\u5173\u952e\u5e93\u548c\u5de5\u5177\u90fd\u652f\u6301\u65b0\u7684Python\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u73af\u5883\u9694\u79bb<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982venv\u6216virtualenv\uff09\u6765\u9694\u79bb\u9879\u76ee\u73af\u5883\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5907\u4efd\u9879\u76ee<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728\u8fdb\u884c\u91cd\u5927\u5347\u7ea7\u4e4b\u524d\uff0c\u5907\u4efd\u9879\u76ee\u6587\u4ef6\u548c\u4f9d\u8d56\u9879\uff0c\u4ee5\u9632\u51fa\u73b0\u610f\u5916\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u5347\u7ea7Python\uff0c\u540c\u65f6\u786e\u4fdd\u9879\u76ee\u7684\u7a33\u5b9a\u6027\u548c\u517c\u5bb9\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528pip\u68c0\u67e5\u5f53\u524dPython\u7248\u672c\uff1f<\/strong><br \/>\u8981\u67e5\u770b\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>python --version<\/code> \u6216 <code>python3 --version<\/code>\u3002\u8fd9\u5c06\u663e\u793a\u60a8\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<p><strong>\u4f7f\u7528pip\u5347\u7ea7Python\u65f6\u9700\u8981\u6ce8\u610f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728\u4f7f\u7528pip\u8fdb\u884cPython\u5347\u7ea7\u65f6\uff0c\u786e\u4fdd\u60a8\u5907\u4efd\u4e86\u91cd\u8981\u7684\u9879\u76ee\u548c\u73af\u5883\uff0c\u56e0\u4e3a\u65b0\u7248\u672c\u53ef\u80fd\u4f1a\u5f15\u5165\u4e0d\u517c\u5bb9\u7684\u66f4\u6539\u3002\u6b64\u5916\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u4ee5\u907f\u514d\u5f71\u54cd\u5168\u5c40\u73af\u5883\u3002<\/p>\n<p><strong>pip\u662f\u5426\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u5b89\u88c5Python\u65b0\u7248\u672c\uff1f<\/strong><br \/>pip\u662f\u4e00\u4e2a\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\uff0c\u800c\u4e0d\u662f\u7528\u6765\u76f4\u63a5\u5b89\u88c5\u6216\u5347\u7ea7Python\u89e3\u91ca\u5668\u672c\u8eab\u3002\u8981\u5347\u7ea7Python\u7248\u672c\uff0c\u901a\u5e38\u9700\u8981\u4ecePython\u5b98\u7f51\u6216\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u679cpip\u4e0d\u5de5\u4f5c\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5982\u679cpip\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u88c5pip\u3002\u4f7f\u7528\u547d\u4ee4<code>python -m ensurepip --upgrade<\/code>\u6765\u91cd\u65b0\u5b89\u88c5pip\u3002\u5982\u679c\u95ee\u9898\u4f9d\u7136\u5b58\u5728\uff0c\u53ef\u4ee5\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u6216\u8003\u8651\u66f4\u65b0Python\u7248\u672c\uff0c\u56e0\u4e3a\u65e7\u7248\u672c\u7684pip\u53ef\u80fd\u4e0e\u65b0\u73af\u5883\u4e0d\u517c\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u4f7f\u7528pip\u5347\u7ea7Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3001\u4f7f\u7528pyenv\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3001 [&hellip;]","protected":false},"author":3,"featured_media":964592,"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\/964586"}],"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=964586"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964586\/revisions"}],"predecessor-version":[{"id":964593,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964586\/revisions\/964593"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/964592"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=964586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=964586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=964586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}