{"id":985122,"date":"2024-12-27T07:34:03","date_gmt":"2024-12-26T23:34:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985122.html"},"modified":"2024-12-27T07:34:05","modified_gmt":"2024-12-26T23:34:05","slug":"vscode%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5python%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985122.html","title":{"rendered":"vscode\u5982\u4f55\u5bfc\u5165python\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212434\/cd3dc09b-8bdb-4f6b-927d-b76748d4afeb.webp\" alt=\"vscode\u5982\u4f55\u5bfc\u5165python\u5e93\" \/><\/p>\n<p><p> <strong>\u5728Visual Studio Code (VSCode)\u4e2d\u5bfc\u5165Python\u5e93\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5Python\u3001\u5b89\u88c5VSCode\u3001\u5b89\u88c5Python\u6269\u5c55\u3001\u8bbe\u7f6ePython\u89e3\u91ca\u5668\u3001\u5b89\u88c5Python\u5e93\u3002<\/strong> \u5b89\u88c5Python\u5e93\u662f\u5176\u4e2d\u7684\u5173\u952e\u6b65\u9aa4\u4e4b\u4e00\uff0c\u8fd9\u901a\u5e38\u901a\u8fc7Python\u5305\u7ba1\u7406\u5de5\u5177pip\u6765\u5b8c\u6210\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4ee5\u53ca\u4e00\u4e9b\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python\u548cVSCode<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528VSCode\u5bfc\u5165Python\u5e93\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86Python\u548cVSCode\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u524d\u5f80Python\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%E7%9A%84Python%E3%80%82\">https:\/\/www.python.org\/\uff09\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\u3002<\/a><\/li>\n<li>\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u9002\u5408\u7684\u5b89\u88c5\u7a0b\u5e8f\uff08Windows\u3001macOS\u6216Linux\uff09\u3002<\/li>\n<li>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528Python\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Visual Studio Code<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u8bbf\u95eeVSCode\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/code.visualstudio.com\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E9%80%82%E5%90%88%E6%82%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84VSCode%E5%AE%89%E8%A3%85%E5%8C%85%E3%80%82\">https:\/\/code.visualstudio.com\/\uff09\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684VSCode\u5b89\u88c5\u5305\u3002<\/a><\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u684c\u9762\u5feb\u6377\u65b9\u5f0f\u6216\u547d\u4ee4\u884c\u542f\u52a8VSCode\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5b89\u88c5Python\u6269\u5c55<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00VSCode<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u542f\u52a8VSCode\u540e\uff0c\u60a8\u5c06\u770b\u5230\u4e00\u4e2a\u6b22\u8fce\u9875\u9762\u6216\u76f4\u63a5\u8fdb\u5165\u7f16\u8f91\u5668\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python\u6269\u5c55<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728VSCode\u4e2d\uff0c\u70b9\u51fb\u5de6\u4fa7\u6d3b\u52a8\u680f\u4e2d\u7684\u6269\u5c55\u56fe\u6807\uff08\u901a\u5e38\u662f\u4e00\u4e2a\u56db\u65b9\u5f62\u56fe\u6807\uff09\u3002<\/li>\n<li>\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201cPython\u201d\uff0c\u627e\u5230\u7531Microsoft\u53d1\u5e03\u7684Python\u6269\u5c55\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u5b89\u88c5\u201d\u6309\u94ae\u4ee5\u5b89\u88c5\u8be5\u6269\u5c55\u3002<\/li>\n<li>\u8be5\u6269\u5c55\u63d0\u4f9b\u4e86Python\u8bed\u8a00\u7684\u652f\u6301\uff0c\u5305\u62ec\u8bed\u6cd5\u9ad8\u4eae\u3001\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u7b49\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u8bbe\u7f6ePython\u89e3\u91ca\u5668<\/p>\n<\/p>\n<ol>\n<li><strong>\u9009\u62e9Python\u89e3\u91ca\u5668<\/strong>\uff1a\n<ul>\n<li>\u6253\u5f00\u4e00\u4e2aPython\u6587\u4ef6\u6216\u5728\u547d\u4ee4\u9762\u677f\uff08Ctrl+Shift+P\u6216Cmd+Shift+P\uff09\u4e2d\u8f93\u5165\u201cPython: Select Interpreter\u201d\u3002<\/li>\n<li>\u5728\u4e0b\u62c9\u83dc\u5355\u4e2d\u9009\u62e9\u60a8\u5b89\u88c5\u7684Python\u7248\u672c\u3002<\/li>\n<li>\u9009\u62e9Python\u89e3\u91ca\u5668\u540e\uff0cVSCode\u5c06\u80fd\u591f\u8bc6\u522b\u5e76\u6267\u884cPython\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5b89\u88c5Python\u5e93<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u7ec8\u7aef\u5b89\u88c5\u5e93<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728VSCode\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u96c6\u6210\u7ec8\u7aef\u6765\u5b89\u88c5Python\u5e93\u3002\u6253\u5f00\u7ec8\u7aef\u7684\u65b9\u6cd5\u662f\u70b9\u51fb\u83dc\u5355\u680f\u4e2d\u7684\u201c\u7ec8\u7aef\u201d-&gt;\u201c\u65b0\u5efa\u7ec8\u7aef\u201d\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5Python\u5e93\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5numpy\u5e93\uff0c\u53ef\u4ee5\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a\n<pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8be5\u547d\u4ee4\u5c06\u5728Python\u73af\u5883\u4e2d\u5b89\u88c5numpy\u5e93\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5b89\u88c5\u5176\u4ed6\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5e93\u7684\u5b89\u88c5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728Python\u6587\u4ef6\u4e2d\u5bfc\u5165\u8be5\u5e93\u4ee5\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u6765\u68c0\u67e5numpy\u662f\u5426\u5df2\u5b89\u88c5\uff1a\n<pre><code class=\"language-python\">import numpy as np<\/p>\n<p>print(np.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u63d0\u793a\u5e76\u8f93\u51fa\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5e93\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u65e0\u6cd5\u8bc6\u522bpip\u547d\u4ee4<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165pip\u547d\u4ee4\u65f6\u51fa\u73b0\u201c\u65e0\u6cd5\u8bc6\u522b\u547d\u4ee4\u201d\u7684\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u6ca1\u6709\u6b63\u786e\u6dfb\u52a0\u5230\u7cfb\u7edfPATH\u4e2d\u3002<\/li>\n<li>\u89e3\u51b3\u65b9\u6cd5\u662f\u5728\u5b89\u88c5Python\u65f6\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u6216\u8005\u624b\u52a8\u5c06Python\u5b89\u88c5\u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u5e93\u65f6\u51fa\u73b0\u6743\u9650\u9519\u8bef<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u5728\u5b89\u88c5\u5e93\u65f6\u51fa\u73b0\u6743\u9650\u9519\u8bef\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884cVSCode\u6216\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528<code>sudo pip install<\/code>\u547d\u4ee4\uff08\u4ec5\u9002\u7528\u4e8emacOS\u548cLinux\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5e93\u7248\u672c\u51b2\u7a81\u6216\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6709\u65f6\u4e0d\u540c\u7684\u5e93\u53ef\u80fd\u4f1a\u6709\u7248\u672c\u51b2\u7a81\u6216\u4f9d\u8d56\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08virtual environment\uff09\u6765\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/li>\n<li>\u5728VSCode\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>python -m venv myenv<\/code>\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u5e76\u901a\u8fc7\u547d\u4ee4<code>source myenv\/bin\/activate<\/code>\uff08macOS\/Linux\uff09\u6216<code>myenv\\Scripts\\activate<\/code>\uff08Windows\uff09\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u987a\u5229\u5728VSCode\u4e2d\u5bfc\u5165\u548c\u4f7f\u7528Python\u5e93\u3002VSCode\u7ed3\u5408Python\u6269\u5c55\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5f00\u53d1\u529f\u80fd\uff0c\u4f7f\u5f97Python\u5f00\u53d1\u66f4\u52a0\u9ad8\u6548\u548c\u4fbf\u6377\u3002\u65e0\u8bba\u662f\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\uff0c\u8fd8\u662fWeb\u5f00\u53d1\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728VSCode\u4e2d\u8f7b\u677e\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728VSCode\u4e2d\u5b89\u88c5Python\u5e93\uff1f<\/strong><br \/>\u5728VSCode\u4e2d\u5b89\u88c5Python\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7ec8\u7aef\u7a97\u53e3\u3002\u6253\u5f00\u7ec8\u7aef\uff08\u53ef\u4ee5\u901a\u8fc7\u83dc\u5355\u201c\u89c6\u56fe\u201d-&gt;\u201c\u7ec8\u7aef\u201d\uff09\uff0c\u7136\u540e\u8f93\u5165\u547d\u4ee4<code>pip install \u5e93\u540d<\/code>\uff0c\u4f8b\u5982<code>pip install numpy<\/code>\u3002\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\uff0c\u5e76\u4e14VSCode\u7684Python\u6269\u5c55\u5df2\u542f\u7528\u3002<\/p>\n<p><strong>VSCode\u662f\u5426\u652f\u6301\u865a\u62df\u73af\u5883\u7684Python\u5e93\u7ba1\u7406\uff1f<\/strong><br \/>\u662f\u7684\uff0cVSCode\u5b8c\u5168\u652f\u6301\u865a\u62df\u73af\u5883\u3002\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u4f7f\u7528\u547d\u4ee4<code>python -m venv env<\/code>\uff0c\u7136\u540e\u6fc0\u6d3b\u5b83\uff08Windows\u4e0a\u4f7f\u7528<code>.\\env\\Scripts\\activate<\/code>\uff0cmacOS\/Linux\u4e0a\u4f7f\u7528<code>source env\/bin\/activate<\/code>\uff09\u3002\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\u4f7f\u7528<code>pip install<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u5e93\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u5168\u5c40\u73af\u5883\u4e2d\u7684\u5e93\u51b2\u7a81\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728VSCode\u4e2d\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\uff1f<\/strong><br \/>\u5728VSCode\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f93\u5165<code>pip list<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u7684\u6240\u6709Python\u5e93\u53ca\u5176\u7248\u672c\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u865a\u62df\u73af\u5883\uff0c\u786e\u4fdd\u5728\u6fc0\u6d3b\u8be5\u73af\u5883\u540e\u518d\u8fd0\u884c\u8be5\u547d\u4ee4\uff0c\u4ee5\u67e5\u770b\u7279\u5b9a\u73af\u5883\u7684\u5e93\u5217\u8868\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Visual Studio Code (VSCode)\u4e2d\u5bfc\u5165Python\u5e93\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5Python\u3001\u5b89\u88c5 [&hellip;]","protected":false},"author":3,"featured_media":985131,"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\/985122"}],"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=985122"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985122\/revisions"}],"predecessor-version":[{"id":985132,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985122\/revisions\/985132"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985131"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}