{"id":70659,"date":"2024-01-31T16:17:28","date_gmt":"2024-01-31T08:17:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=70659"},"modified":"2024-01-31T16:46:45","modified_gmt":"2024-01-31T08:46:45","slug":"%e6%80%8e%e6%a0%b7%e5%8f%af%e4%bb%a5%e8%a7%a3%e5%86%b3-python-%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85%e8%bf%87%e7%a8%8b%e4%b8%ad%e7%9a%84%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/70659.html","title":{"rendered":"\u600e\u6837\u53ef\u4ee5\u89e3\u51b3 Python \u6a21\u5757\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u7684\u9519\u8bef"},"content":{"rendered":"<p><strong>\u89e3\u51b3Python\u6a21\u5757\u5b89\u88c5\u9519\u8bef\u7684\u7b56\u7565\u4e3b\u8981\u5305\u62ec\u68c0\u67e5Python\u73af\u5883\u3001\u4f7f\u7528\u5408\u9002\u7684\u5b89\u88c5\u547d\u4ee4\u3001\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u68c0\u67e5\u7f16\u8bd1\u5de5\u5177\u94fe\u3001\u67e5\u8be2\u9519\u8bef\u65e5\u5fd7\u3001\u8003\u8651\u64cd\u4f5c\u7cfb\u7edf\u56e0\u7d20<\/strong>\u3002\u7740\u91cd\u8bb2\u89e3<strong>\u4f9d\u8d56\u95ee\u9898<\/strong>\uff0c\u6bd4\u5982\u4e0d\u540c\u6a21\u5757\u95f4\u53ef\u80fd\u5b58\u5728\u4f9d\u8d56\u7684\u7279\u5b9a\u7248\u672c\uff0c\u88c5\u5176\u4ed6\u6a21\u5757\u524d\u9700\u5148\u88c5\u597d\u8fd9\u4e9b\u4f9d\u8d56\uff0c\u6216\u8005\u786e\u8ba4\u6a21\u5757\u4e0e\u73b0\u6709\u7cfb\u7edf\u548cPython\u7248\u672c\u7684\u517c\u5bb9\u6027\u3002<\/p>\n<h2><strong>\u4e00\u3001\u68c0\u67e5PYTHON\u73af\u5883\u914d\u7f6e<\/strong><\/h2>\n<p>\u5b89\u88c5Python\u6a21\u5757\u524d\uff0c\u4fdd\u8bc1Python\u73af\u5883\u914d\u7f6e\u6b63\u786e\u662f\u5173\u952e\u3002\u8fd9\u4e00\u6b65\u5305\u62ec\u786e\u8ba4Python\u7248\u672c\u548c\u8def\u5f84\u8bbe\u7f6e\u3002\u8981\u5b89\u88c5\u6a21\u5757\uff0c\u6b63\u786e\u7684Python\u7248\u672c\u548c\u76f8\u5e94\u7684pip\u7248\u672c\u5fc5\u4e0d\u53ef\u5c11\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8ePython 2.x\uff0c\u901a\u5e38\u4f7f\u7528pip\u547d\u4ee4\uff0c\u800c\u5bf9\u4e8ePython 3.x\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528pip3\u3002\u9a8c\u8bc1\u6267\u884c `python &#8211;version` \u548c `pip &#8211;version` \u6216 `pip3 &#8211;version` \u6765\u786e\u8ba4\u7248\u672c\u548c\u662f\u5426\u5b89\u88c5\u4e86pip\u3002<\/p>\n<h2><strong>\u4e8c\u3001\u91c7\u7528\u5408\u9002\u7684\u5b89\u88c5\u547d\u4ee4<\/strong><\/h2>\n<p>\u4e0d\u540c\u7684\u5b89\u88c5\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u60c5\u51b5\u3002\u4f8b\u5982\uff0c\u76f4\u63a5\u4f7f\u7528 `pip install package-name` \u53ef\u5b89\u88c5\u5927\u591a\u6570\u5e93\uff0c\u7136\u800c\u6709\u65f6\u53ef\u80fd\u9700\u8981 `pip install package-name &#8211;user` \u6765\u6307\u5b9a\u7528\u6237\u7ea7\u7684\u5b89\u88c5\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u662f\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\uff0c\u53ef\u80fd\u9700\u8981\u7528\u5230 `python setup.py install`\u3002\u6b64\u5916\uff0c\u6709\u4e9b\u6a21\u5757\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684\u5b89\u88c5\u53c2\u6570\uff0c\u56e0\u6b64\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u662f\u5173\u952e\u3002<\/p>\n<h2><strong>\u4e09\u3001\u89e3\u51b3\u4f9d\u8d56\u51b2\u7a81\u95ee\u9898<\/strong><\/h2>\n<p>\u4f9d\u8d56\u95ee\u9898\u5e38\u4f1a\u5bfc\u81f4\u6a21\u5757\u5b89\u88c5\u5931\u8d25\u3002\u6a21\u5757\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u590d\u6742\uff0c\u4e14\u53ef\u80fd\u8981\u6c42\u7279\u5b9a\u7248\u672c\u7684\u4f9d\u8d56\u5e93\u3002\u4f7f\u7528 `pip install package-name` \u65f6\uff0cpip\u4f1a\u5c1d\u8bd5\u89e3\u51b3\u8fd9\u4e9b\u4f9d\u8d56\u95ee\u9898\uff0c\u4f46\u975e\u603b\u80fd\u6210\u529f\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\u6a21\u5757\u7684\u4f9d\u8d56\u9879\uff0c\u6216\u8005\u4f7f\u7528 `pip install package-name==version-number` \u6765\u5b89\u88c5\u786e\u5207\u7684\u7248\u672c\u3002<\/p>\n<h2><strong>\u56db\u3001\u5229\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406\u5305<\/strong><\/h2>\n<p>\u865a\u62df\u73af\u5883\u5728\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u4e2d\u8d77\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u901a\u8fc7\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\uff0c\u53ef\u4ee5\u907f\u514d\u7cfb\u7edf\u7ea7\u7684\u5305\u51b2\u7a81\u548c\u7248\u672c\u95ee\u9898\u3002\u4f7f\u7528 `virtualenv` \u6216 `conda` \u7b49\u5de5\u5177\u53ef\u4ee5\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u7136\u540e\u5728\u6b64\u73af\u5883\u5185\u5b89\u88c5\u6240\u9700\u7684\u6a21\u5757\uff0c\u4ece\u800c\u4fdd\u6301\u9879\u76ee\u7684\u4f9d\u8d56\u9694\u79bb\u3002<\/p>\n<h2><strong>\u4e94\u3001\u68c0\u67e5\u7f16\u8bd1\u5de5\u5177\u94fe<\/strong><\/h2>\n<p>\u4e00\u4e9bPython\u6a21\u5757\u9700\u8981\u7f16\u8bd1\u6269\u5c55\uff0c\u8fd9\u5c31\u8981\u6c42\u7cfb\u7edf\u4e2d\u8981\u5b89\u88c5\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u548c\u5f00\u53d1\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u5728Windows\u5e73\u53f0\u4e0a\uff0c\u53ef\u80fd\u9700\u8981Microsoft Visual C++\u7f16\u8bd1\u5668\u6765\u6784\u5efa\u67d0\u4e9b\u6a21\u5757\u3002\u786e\u4fdd\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u4e86\u5fc5\u8981\u7684\u5de5\u5177\u548c\u5e93\uff0c\u8fd9\u5bf9\u4e8e\u7f16\u8bd1\u578b\u6a21\u5757\u7684\u5b89\u88c5\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<h2><strong>\u516d\u3001\u67e5\u8be2\u9519\u8bef\u65e5\u5fd7\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f<\/strong><\/h2>\n<p>\u5b89\u88c5\u5931\u8d25\u65f6\uff0c\u9519\u8bef\u65e5\u5fd7\u662f\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u3002pip\u901a\u5e38\u4f1a\u663e\u793a\u9519\u8bef\u4fe1\u606f\uff0c\u8fd9\u4e9b\u4fe1\u606f\u53ef\u4ee5\u63d0\u4f9b\u5173\u4e8e\u53d1\u751f\u4e86\u4ec0\u4e48\u95ee\u9898\u7684\u7ebf\u7d22\u3002\u8981\u89e3\u51b3\u5b89\u88c5\u9519\u8bef\uff0c\u987b\u4ed4\u7ec6\u9605\u8bfb\u8fd9\u4e9b\u8f93\u51fa\u4fe1\u606f\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u4e86\u5173\u4e8e\u7f3a\u5931\u7684\u4f9d\u8d56\u9879\u3001\u4e0d\u517c\u5bb9\u7684\u7248\u672c\u6216\u5176\u4ed6\u6f5c\u5728\u95ee\u9898\u7684\u4fe1\u606f\u3002<\/p>\n<h2><strong>\u4e03\u3001\u8003\u8651\u64cd\u4f5c\u7cfb\u7edf\u7279\u6709\u7684\u95ee\u9898<\/strong><\/h2>\n<p>\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u95f4\u53ef\u80fd\u5b58\u5728\u73af\u5883\u5dee\u5f02\uff0c\u8fd9\u4e9b\u5dee\u5f02\u53ef\u5bfc\u81f4\u6a21\u5757\u5b89\u88c5\u5931\u8d25\u3002\u6bd4\u5982\uff0cLinux\u7cfb\u7edf\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7684\u5e93\u6587\u4ef6\u624d\u80fd\u4f7f\u67d0\u4e9b\u6a21\u5757\u6b63\u5e38\u5de5\u4f5c\uff0c\u800cmacOS\u7cfb\u7edf\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u8981\u6c42\u989d\u5916\u7684\u5b89\u5168\u6743\u9650\u914d\u7f6e\u3002\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u9002\u5f53\u914d\u7f6e\u6216\u8c03\u6574\u53ef\u5e2e\u52a9\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u3002<\/p>\n<p> <strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><strong>\u5982\u4f55\u89e3\u51b3Python\u6a21\u5757\u5b89\u88c5\u65f6\u9047\u5230\u7684 \u201cno module named\u201d \u9519\u8bef\uff1f<\/strong><\/p>\n<p>1. <strong>\u68c0\u67e5Python\u73af\u5883\uff1a<\/strong> \u786e\u4fdd\u4f60\u5728\u6b63\u786e\u7684Python\u73af\u5883\u4e0b\u5b89\u88c5\u6a21\u5757\u3002\u4f7f\u7528 `python &#8211;version` \u53ef\u4ee5\u786e\u8ba4\u4f60\u7684Python\u7248\u672c\uff0c\u800c\u4f7f\u7528 `pip &#8211;version` \u53ef\u4ee5\u786e\u8ba4\u4f60\u7684pip\u7248\u672c\u3002\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f\u865a\u62df\u73af\u5883\uff08virtual environment\uff09\uff0c\u5219\u8981\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\u518d\u5b89\u88c5\u6a21\u5757\u3002<\/p>\n<p>2. <strong>\u66f4\u65b0pip\uff1a<\/strong> \u6709\u65f6\u65e7\u7248\u672c\u7684pip\u53ef\u80fd\u4f1a\u5bfc\u81f4\u95ee\u9898\uff0c\u4f7f\u7528\u547d\u4ee4 `pip install &#8211;upgrade pip` \u53ef\u4ee5\u66f4\u65b0pip\u5230\u6700\u65b0\u7248\u672c\u3002<\/p>\n<p>3. <strong>\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\uff1a<\/strong> \u786e\u4fdd\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u7a33\u5b9a\uff0c\u6709\u65f6\u7f51\u7edc\u95ee\u9898\u4f1a\u5bfc\u81f4\u6a21\u5757\u5b89\u88c5\u5931\u8d25\u3002<\/p>\n<p>4. <strong>\u5b89\u88c5\u4f9d\u8d56\u5e93\uff1a<\/strong> \u67d0\u4e9bPython\u6a21\u5757\u7684\u5b89\u88c5\u9700\u8981\u4f9d\u8d56\u5176\u4ed6\u7684\u5e93\uff0c\u5982\u679c\u4f60\u9047\u5230\u4e86\u4f9d\u8d56\u9519\u8bef\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u5148\u5b89\u88c5\u4f9d\u8d56\u5e93\u3002\u4f60\u53ef\u4ee5\u4ece\u6a21\u5757\u7684\u5b98\u65b9\u6587\u6863\u4e2d\u627e\u5230\u6240\u9700\u7684\u4f9d\u8d56\u4fe1\u606f\u3002<\/p>\n<p>5. <strong>\u4f7f\u7528\u6e05\u534e\u955c\u50cf\u6e90\uff1a<\/strong> \u5728\u4e2d\u56fd\u5927\u9646\u5730\u533a, \u7531\u4e8e\u7f51\u7edc\u95ee\u9898\uff0c\u901a\u5e38\u4f1a\u5bfc\u81f4\u4f7f\u7528 pip \u5b89\u88c5\u65f6\u901f\u5ea6\u7f13\u6162\u751a\u81f3\u5931\u8d25\uff0c\u53ef\u4ee5\u8003\u8651\u914d\u7f6e\u6e05\u534e\u955c\u50cf\u6e90\uff0c\u52a0\u5feb\u4e0b\u8f7d\u901f\u5ea6\u3002<\/p>\n<p>6. <strong>\u67e5\u770b\u9519\u8bef\u4fe1\u606f\uff1a<\/strong> \u5f53\u6a21\u5757\u5b89\u88c5\u5931\u8d25\u65f6\uff0c\u9519\u8bef\u4fe1\u606f\u4f1a\u7ed9\u51fa\u4e00\u4e9b\u7ebf\u7d22\uff0c\u53ef\u4ee5\u6839\u636e\u8fd9\u4e9b\u4fe1\u606f\u6765\u89e3\u51b3\u95ee\u9898\uff0c\u6709\u65f6\u95ee\u9898\u53ef\u80fd\u5728\u4e8e\u7cfb\u7edf\u7f3a\u5c11\u4e00\u4e9b\u4f9d\u8d56\u5e93\u6216\u5de5\u5177\u3002<\/p>\n<p>7. <strong>\u5c1d\u8bd5\u4f7f\u7528conda\uff1a<\/strong> \u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fAnaconda\u53d1\u884c\u7248\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528conda\u6765\u5b89\u88c5\u6a21\u5757\uff0c\u6709\u65f6\u5b83\u4f1a\u6bd4pip\u66f4\u5bb9\u6613\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898\u3002<\/p>\n<p>\u8bb0\u4f4f\uff0c\u5728\u641c\u7d22\u89e3\u51b3\u65b9\u6848\u65f6\uff0c\u4e00\u5b9a\u5148\u8981\u5c06\u9519\u8bef\u4fe1\u606f\u590d\u5236\u7c98\u8d34\uff0c\u8fd9\u6837\u80fd\u66f4\u65b9\u4fbf\u5730\u627e\u5230\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u89e3\u51b3Python\u6a21\u5757\u5b89\u88c5\u9519\u8bef\u7684\u7b56\u7565\u4e3b\u8981\u5305\u62ec\u68c0\u67e5Python\u73af\u5883\u3001\u4f7f\u7528\u5408\u9002\u7684\u5b89\u88c5\u547d\u4ee4\u3001\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883 [&hellip;]","protected":false},"author":1,"featured_media":70664,"comment_status":"closed","ping_status":"closed","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\/70659"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=70659"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/70659\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/70664"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=70659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=70659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=70659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}