{"id":1010217,"date":"2024-12-27T11:18:59","date_gmt":"2024-12-27T03:18:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1010217.html"},"modified":"2024-12-27T11:19:04","modified_gmt":"2024-12-27T03:19:04","slug":"python%e5%a6%82%e4%bd%95%e6%9b%b4%e6%96%b0%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1010217.html","title":{"rendered":"python\u5982\u4f55\u66f4\u65b0\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084834\/1aa016e1-c796-4f36-8e24-c8d6b7ca77a1.webp\" alt=\"python\u5982\u4f55\u66f4\u65b0\u5305\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u66f4\u65b0\u5305\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528pip\u547d\u4ee4\u3001\u4f7f\u7528conda\u547d\u4ee4\u3001\u624b\u52a8\u66f4\u65b0\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528pip\u662f\u6700\u5e38\u89c1\u548c\u7b80\u4fbf\u7684\u65b9\u5f0f\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pip\u547d\u4ee4\u66f4\u65b0Python\u5305\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528pip\u547d\u4ee4\u66f4\u65b0Python\u5305\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u3002Pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u51e0\u4e4e\u6240\u6709\u7684Python\u5305\u90fd\u53ef\u4ee5\u901a\u8fc7pip\u6765\u7ba1\u7406\u3002\u8981\u66f4\u65b0\u5305\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86pip\uff0c\u5e76\u4e14pip\u7248\u672c\u662f\u6700\u65b0\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u66f4\u65b0pip\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<p><p>\u4f7f\u7528pip\u66f4\u65b0\u5305\u7684\u57fa\u672c\u547d\u4ee4\u683c\u5f0f\u662f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade &lt;package_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d<code>&lt;package_name&gt;<\/code>\u662f\u4f60\u60f3\u8981\u66f4\u65b0\u7684\u5305\u7684\u540d\u79f0\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u4ecePython\u5305\u7d22\u5f15\uff08PyPI\uff09\u4e2d\u83b7\u53d6\u6700\u65b0\u7684\u7248\u672c\u5e76\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528PIP\u547d\u4ee4\u66f4\u65b0\u5305<\/h3>\n<\/p>\n<p><p><strong>1. \u68c0\u67e5\u5f53\u524d\u5305\u7684\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u66f4\u65b0\u5305\u4e4b\u524d\uff0c\u9996\u5148\u5efa\u8bae\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684\u5305\u7684\u7248\u672c\uff0c\u4ee5\u4fbf\u786e\u8ba4\u66f4\u65b0\u524d\u540e\u7684\u53d8\u5316\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770b\u67d0\u4e2a\u5305\u7684\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip show &lt;package_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a\u5305\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u53f7\u3001\u5b89\u88c5\u4f4d\u7f6e\u7b49\u3002<\/p>\n<\/p>\n<p><p><strong>2. \u66f4\u65b0\u7279\u5b9a\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u66f4\u65b0\u5305\u7684\u6700\u76f4\u63a5\u65b9\u6cd5\u662f\u4f7f\u7528<code>pip install --upgrade<\/code>\u547d\u4ee4\u3002\u8fd9\u4f1a\u4ecePython\u5305\u7d22\u5f15\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7684\u7248\u672c\u3002\u4f8b\u5982\uff0c\u8981\u66f4\u65b0<code>requests<\/code>\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u548c\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684<code>requests<\/code>\u5305\u3002<\/p>\n<\/p>\n<p><p><strong>3. \u66f4\u65b0\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u867d\u7136\u4e0d\u5efa\u8bae\u9891\u7e41\u66f4\u65b0\u6240\u6709\u5305\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u786e\u4fdd\u6240\u6709\u5305\u90fd\u662f\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u66f4\u65b0\u6240\u6709\u5b89\u88c5\u7684\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list --outdated --format=freeze | grep -v &#39;^\\-e&#39; | cut -d = -f 1 | xargs -n1 pip install -U<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5217\u51fa\u6240\u6709\u8fc7\u65f6\u7684\u5305\uff0c\u5e76\u9010\u4e00\u66f4\u65b0\u5b83\u4eec\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528CONDA\u547d\u4ee4\u66f4\u65b0\u5305<\/h3>\n<\/p>\n<p><p><strong>1. \u4f7f\u7528conda\u7ba1\u7406\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4f7f\u7528Anaconda\u53d1\u884c\u7248\u7684\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528<code>conda<\/code>\u6765\u66f4\u65b0\u5305\u3002<code>Conda<\/code>\u662f\u4e00\u4e2a\u5f00\u6e90\u5305\u7ba1\u7406\u7cfb\u7edf\u548c\u73af\u5883\u7ba1\u7406\u7cfb\u7edf\uff0c\u5b83\u53ef\u4ee5\u5b89\u88c5\u548c\u7ba1\u7406\u8f6f\u4ef6\u5305\uff0c\u5e76\u5728\u4e0d\u540c\u7684\u73af\u5883\u4e2d\u5207\u6362\u3002\u4f7f\u7528<code>conda<\/code>\u66f4\u65b0\u5305\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda update &lt;package_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4f1a\u66f4\u65b0\u6307\u5b9a\u7684\u5305\u5230\u5f53\u524d\u53ef\u7528\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p><strong>2. \u66f4\u65b0\u6240\u6709\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u66f4\u65b0\u6240\u6709\u4f7f\u7528<code>conda<\/code>\u5b89\u88c5\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda update --all<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u66f4\u65b0\u6240\u6709\u5b89\u88c5\u7684\u5305\u5230\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u624b\u52a8\u66f4\u65b0\u5305<\/h3>\n<\/p>\n<p><p><strong>1. \u4e0b\u8f7d\u6700\u65b0\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u67d0\u4e9b\u5305\u53ef\u80fd\u4e0d\u5728Python\u5305\u7d22\u5f15\u4e2d\uff0c\u6216\u8005\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684\u5305\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u624b\u52a8\u4e0b\u8f7d\u5305\u5e76\u5b89\u88c5\u3002\u9996\u5148\uff0c\u8bbf\u95ee\u5305\u7684\u5b98\u65b9\u7f51\u7ad9\u6216\u8005GitHub\u4ed3\u5e93\uff0c\u4e0b\u8f7d\u6700\u65b0\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p><strong>2. \u5b89\u88c5\u4e0b\u8f7d\u7684\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u89e3\u538b\u7f29\u6587\u4ef6\uff0c\u5e76\u5728\u89e3\u538b\u540e\u7684\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4f1a\u5b89\u88c5\u4e0b\u8f7d\u7684\u5305\u3002\u5982\u679c\u9700\u8981\u66f4\u65b0\uff0c\u53ef\u4ee5\u91cd\u590d\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5e76\u786e\u4fdd\u5220\u9664\u65e7\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p><strong>1. \u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u5141\u8bb8\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u521b\u5efa\u591a\u4e2a\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u6bcf\u4e2a\u73af\u5883\u90fd\u6709\u81ea\u5df1\u7684\u5305\u96c6\u5408\u548c\u914d\u7f6e\u3002\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u5305\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p><strong>2. \u6fc0\u6d3b\u548c\u66f4\u65b0\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u5728\u5176\u4e2d\u5b89\u88c5\u548c\u66f4\u65b0\u5305\uff0c\u800c\u4e0d\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\u3002\u6fc0\u6d3b\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p>Windows:<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>macOS\u548cLinux:<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u524d\u9762\u63d0\u5230\u7684<code>pip<\/code>\u6216<code>conda<\/code>\u547d\u4ee4\u66f4\u65b0\u5305\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u66f4\u65b0Python\u5305\u65f6\uff0c<strong>\u786e\u4fdd\u5907\u4efd\u9879\u76ee\u73af\u5883<\/strong>\u548c<strong>\u4e86\u89e3\u4f9d\u8d56\u5173\u7cfb<\/strong>\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4e0d\u540c\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7248\u672c\u7684\u5305\uff0c\u9891\u7e41\u66f4\u65b0\u53ef\u80fd\u5bfc\u81f4\u4e0d\u517c\u5bb9\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u5305\u66f4\u65b0\u4e4b\u524d\uff0c\u5efa\u8bae\u5728\u865a\u62df\u73af\u5883\u4e2d\u6d4b\u8bd5\u66f4\u65b0\uff0c\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u7a33\u5b9a\u6027\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u66f4\u65b0\u5305\u53ef\u4ee5\u83b7\u5f97\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u4fee\u590d\uff0c\u4f46\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5e94\u8c28\u614e\u64cd\u4f5c\uff0c\u4ee5\u514d\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u98ce\u9669\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u68c0\u67e5\u5df2\u5b89\u88c5\u5305\u7684\u7248\u672c\uff1f<\/strong><br \/>\u8981\u67e5\u770b\u5f53\u524d\u5df2\u5b89\u88c5\u5305\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7<code>pip show \u5305\u540d<\/code>\u6765\u67e5\u770b\u7279\u5b9a\u5305\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u53f7\u3001\u4f9d\u8d56\u5173\u7cfb\u7b49\u3002<\/p>\n<p><strong>\u66f4\u65b0Python\u5305\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u66f4\u65b0\u5305\u4e4b\u524d\uff0c\u5efa\u8bae\u5907\u4efd\u4f60\u7684\u9879\u76ee\u73af\u5883\uff0c\u7279\u522b\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u3002\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5305\u7248\u672c\u51b2\u7a81\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u9605\u8bfb\u66f4\u65b0\u5305\u7684\u53d8\u66f4\u65e5\u5fd7\uff0c\u4ee5\u4e86\u89e3\u65b0\u7248\u672c\u53ef\u80fd\u5e26\u6765\u7684\u7834\u574f\u6027\u66f4\u6539\u6216\u65b0\u529f\u80fd\u3002<\/p>\n<p><strong>\u5982\u679c\u66f4\u65b0\u5305\u540e\u51fa\u73b0\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u5e94\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u5982\u679c\u66f4\u65b0\u5305\u540e\u9047\u5230\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u56de\u9000\u5230\u4e4b\u524d\u7684\u7248\u672c\u3002\u4f7f\u7528<code>pip install \u5305\u540d==\u7248\u672c\u53f7<\/code>\u53ef\u4ee5\u6307\u5b9a\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684\u5305\u3002\u53e6\u5916\uff0c\u8003\u8651\u4f7f\u7528<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u6765\u4fdd\u5b58\u5f53\u524d\u73af\u5883\u7684\u5305\u7248\u672c\uff0c\u4ee5\u4fbf\u5c06\u6765\u9700\u8981\u6062\u590d\u65f6\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u66f4\u65b0\u5305\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528pip\u547d\u4ee4\u3001\u4f7f\u7528conda\u547d\u4ee4\u3001\u624b\u52a8\u66f4\u65b0\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1010228,"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\/1010217"}],"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=1010217"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1010217\/revisions"}],"predecessor-version":[{"id":1010230,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1010217\/revisions\/1010230"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1010228"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1010217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1010217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1010217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}