{"id":942367,"date":"2024-12-26T22:01:36","date_gmt":"2024-12-26T14:01:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/942367.html"},"modified":"2024-12-26T22:01:38","modified_gmt":"2024-12-26T14:01:38","slug":"python%e5%a6%82%e4%bd%95%e6%9b%b4%e6%94%b9%e6%ba%90","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/942367.html","title":{"rendered":"python\u5982\u4f55\u66f4\u6539\u6e90"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080222\/03b574cf-294a-4f27-bf8f-7f106c192f24.webp\" alt=\"python\u5982\u4f55\u66f4\u6539\u6e90\" \/><\/p>\n<p><p> <strong>Python\u66f4\u6539\u6e90\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\u3001\u4e34\u65f6\u66f4\u6539\u6e90\u3001\u6c38\u4e45\u66f4\u6539\u6e90\u3001\u4ee5\u53ca\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u8bbe\u7f6e\u3002\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u63d0\u5347\u4e0b\u8f7d\u901f\u5ea6\u3001\u89e3\u51b3\u7f51\u7edc\u9650\u5236\u95ee\u9898\uff0c\u5e76\u63d0\u9ad8\u5305\u7ba1\u7406\u7684\u6548\u7387\u3002<\/strong>\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\u662f\u975e\u5e38\u63a8\u8350\u7684\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u955c\u50cf\u6e90\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5feb\u7684\u8bbf\u95ee\u901f\u5ea6\uff0c\u5e76\u4e14\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u540c\u6b65\u6027\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u5404\u79cd\u65b9\u5f0f\u66f4\u6539Python\u7684\u6e90\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\u662f\u66f4\u6539Python\u6e90\u7684\u5e38\u7528\u65b9\u6cd5\u3002\u56fd\u5185\u955c\u50cf\u6e90\u901a\u5e38\u4f1a\u4e0e\u5b98\u65b9\u6e90\u4fdd\u6301\u540c\u6b65\uff0c\u5e76\u63d0\u4f9b\u66f4\u5feb\u7684\u8bbf\u95ee\u901f\u5ea6\u3002\u5e38\u7528\u7684\u56fd\u5185\u955c\u50cf\u6e90\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6e05\u534e\u5927\u5b66\uff1a<code>https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/code><\/li>\n<li>\u963f\u91cc\u4e91\uff1a<code>https:\/\/mirrors.aliyun.com\/pypi\/simple\/<\/code><\/li>\n<li>\u8c46\u74e3\uff1a<code>https:\/\/pypi.douban.com\/simple\/<\/code><\/li>\n<li>\u817e\u8baf\u4e91\uff1a<code>https:\/\/mirrors.cloud.tencent.com\/pypi\/simple<\/code><\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4e34\u65f6\u66f4\u6539\u6e90<\/h3>\n<\/p>\n<p><p>\u5728\u5b89\u88c5Python\u5305\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6307\u5b9a\u4f7f\u7528\u7684\u6e90\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u4e34\u65f6\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u6e90\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install package_name -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ea\u5bf9\u5f53\u524d\u547d\u4ee4\u6709\u6548\uff0c\u4e0d\u4f1a\u5f71\u54cd\u540e\u7eed\u7684\u5b89\u88c5\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6c38\u4e45\u66f4\u6539\u6e90<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5e0c\u671b\u6bcf\u6b21\u5b89\u88c5\u5305\u65f6\u90fd\u4f7f\u7528\u7279\u5b9a\u7684\u6e90\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u6c38\u4e45\u66f4\u6539\u3002<\/p>\n<\/p>\n<p><h4>1. Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u5728\u7528\u6237\u76ee\u5f55\u4e0b\u521b\u5efa\u6216\u7f16\u8f91<code>pip<\/code>\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>notepad %APPDATA%\\pip\\pip.ini<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-ini\">[global]<\/p>\n<p>index-url = https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u4fdd\u5b58\u5e76\u5173\u95ed\u6587\u4ef6\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\u53ef\u4ee5\u7f16\u8f91<code>pip<\/code>\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>nano ~\/.pip\/pip.conf<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-ini\">[global]<\/p>\n<p>index-url = https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u4fdd\u5b58\u5e76\u9000\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u4f7f\u5f97\u6bcf\u6b21\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u5305\u65f6\uff0c\u90fd\u9ed8\u8ba4\u4f7f\u7528\u6307\u5b9a\u7684\u955c\u50cf\u6e90\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u4e0a\u9762\u7684\u65b9\u6cd5\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7684\u65b9\u5f0f\u6765\u66f4\u6539Python\u7684\u6e90\u3002\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u7075\u6d3b\uff0c\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><h4>1. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u5728Linux\u548cmacOS\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>export<\/code>\u547d\u4ee4\u6765\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PIP_INDEX_URL=https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u5c5e\u6027-&gt;\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e-&gt;\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u6e90\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u8bbe\u7f6e\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u5e76\u5728\u865a\u62df\u73af\u5883\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u6e90\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv env<\/p>\n<p>source env\/bin\/activate<\/p>\n<p>pip config set global.index-url https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u865a\u62df\u73af\u5883\u8bbe\u7f6e\u7684\u6e90\u53ea\u4f1a\u5f71\u54cd\u5f53\u524d\u865a\u62df\u73af\u5883\u4e2d\u7684\u5305\u7ba1\u7406\uff0c\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u5168\u5c40\u7684\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<ol>\n<li><strong>\u9009\u62e9\u7a33\u5b9a\u7684\u955c\u50cf\u6e90<\/strong>\uff1a\u5728\u9009\u62e9\u955c\u50cf\u6e90\u65f6\uff0c\u5c3d\u91cf\u9009\u62e9\u7a33\u5b9a\u4e14\u4e0e\u5b98\u65b9\u540c\u6b65\u7684\u6e90\uff0c\u4ee5\u4fdd\u8bc1\u5305\u7684\u5b8c\u6574\u6027\u548c\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u5b9a\u671f\u68c0\u67e5\u955c\u50cf\u6e90\u72b6\u6001<\/strong>\uff1a\u955c\u50cf\u6e90\u7684\u72b6\u6001\u53ef\u80fd\u4f1a\u53d8\u5316\uff0c\u5efa\u8bae\u5b9a\u671f\u68c0\u67e5\u955c\u50cf\u6e90\u7684\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u4e86\u89e3\u955c\u50cf\u6e90\u7684\u9650\u5236<\/strong>\uff1a\u4e00\u4e9b\u955c\u50cf\u6e90\u53ef\u80fd\u5bf9\u67d0\u4e9b\u5305\u6709\u9650\u5236\uff0c\u5b89\u88c5\u65f6\u9700\u8981\u6ce8\u610f\u662f\u5426\u6709\u4f9d\u8d56\u7f3a\u5931\u7684\u95ee\u9898\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u66f4\u6539Python\u7684\u6e90\uff0c\u63d0\u9ad8\u5305\u7ba1\u7406\u7684\u6548\u7387\u548c\u4e0b\u8f7d\u901f\u5ea6\u3002\u6839\u636e\u5177\u4f53\u7684\u4f7f\u7528\u573a\u666f\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u4ee5\u83b7\u5f97\u6700\u4f73\u7684\u4f7f\u7528\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u66f4\u6539Python\u7684\u9ed8\u8ba4\u6e90\u4ee5\u52a0\u5feb\u5305\u5b89\u88c5\u901f\u5ea6\uff1f<\/strong><br \/>\u66f4\u6539Python\u7684\u9ed8\u8ba4\u6e90\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5305\u7684\u4e0b\u8f7d\u901f\u5ea6\uff0c\u7279\u522b\u662f\u5728\u4e2d\u56fd\u7b49\u5730\u533a\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>pip<\/code>\u7684\u914d\u7f6e\u6587\u4ef6\u6765\u5b9e\u73b0\u3002\u5177\u4f53\u6b65\u9aa4\u4e3a\uff1a\u5728\u7528\u6237\u76ee\u5f55\u4e0b\u627e\u5230\u6216\u521b\u5efa<code>.pip<\/code>\u6587\u4ef6\u5939\uff0c\u7136\u540e\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a<code>pip.conf<\/code>\u6587\u4ef6\uff0c\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a  <\/p>\n<pre><code>[global]\nindex-url = https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\n<\/code><\/pre>\n<p>\u8fd9\u4f1a\u5c06\u9ed8\u8ba4\u6e90\u66f4\u6539\u4e3a\u6e05\u534e\u5927\u5b66\u7684\u955c\u50cf\u6e90\u3002\u4f60\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6\u955c\u50cf\u6e90\uff0c\u5982\u963f\u91cc\u4e91\u3001\u8c46\u74e3\u7b49\uff0c\u4f7f\u7528\u76f8\u5e94\u7684URL\u5373\u53ef\u3002<\/p>\n<p><strong>\u66f4\u6539\u6e90\u540e\uff0c\u5982\u4f55\u9a8c\u8bc1\u65b0\u7684\u6e90\u662f\u5426\u751f\u6548\uff1f<\/strong><br \/>\u8981\u9a8c\u8bc1\u65b0\u7684\u6e90\u662f\u5426\u751f\u6548\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a  <\/p>\n<pre><code>pip config list\n<\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u4f1a\u663e\u793a\u5f53\u524d\u7684\u914d\u7f6e\uff0c\u5305\u62ec\u6e90\u5730\u5740\u3002\u4f60\u4e5f\u53ef\u4ee5\u5c1d\u8bd5\u5b89\u88c5\u4e00\u4e2a\u5305\uff0c\u4f8b\u5982<code>numpy<\/code>\uff0c\u770b\u662f\u5426\u80fd\u4ece\u65b0\u7684\u6e90\u5feb\u901f\u4e0b\u8f7d\u3002\u82e5\u80fd\u987a\u5229\u5b89\u88c5\uff0c\u8bf4\u660e\u66f4\u6539\u5df2\u751f\u6548\u3002<\/p>\n<p><strong>\u5728\u66f4\u6539\u6e90\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5982\u679c\u5728\u66f4\u6539\u6e90\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a  <\/p>\n<ol>\n<li>\u786e\u4fdd\u7f51\u7edc\u8fde\u63a5\u6b63\u5e38\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u65b0\u7684\u6e90\u5730\u5740\u786e\u8ba4\u53ef\u7528\u6027\u3002  <\/li>\n<li>\u68c0\u67e5<code>pip.conf<\/code>\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\u662f\u5426\u6b63\u786e\uff0c\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u6ca1\u6709\u9519\u8bef\u3002  <\/li>\n<li>\u5982\u679c\u4f9d\u7136\u65e0\u6cd5\u89e3\u51b3\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528<code>--index-url<\/code>\u53c2\u6570\u4e34\u65f6\u66f4\u6539\u6e90\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<pre><code>pip install numpy --index-url=https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u76f4\u63a5\u5728\u5b89\u88c5\u65f6\u6307\u5b9a\u6e90\uff0c\u907f\u514d\u914d\u7f6e\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u66f4\u6539\u6e90\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\u3001\u4e34\u65f6\u66f4\u6539\u6e90\u3001\u6c38\u4e45\u66f4\u6539\u6e90\u3001\u4ee5\u53ca\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u8bbe\u7f6e\u3002\u8fd9\u4e9b\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":942369,"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\/942367"}],"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=942367"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/942367\/revisions"}],"predecessor-version":[{"id":942372,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/942367\/revisions\/942372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/942369"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=942367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=942367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=942367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}