{"id":175747,"date":"2024-05-08T18:57:04","date_gmt":"2024-05-08T10:57:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/175747.html"},"modified":"2024-05-08T18:57:16","modified_gmt":"2024-05-08T10:57:16","slug":"visual-studio-code%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e9%85%8d%e7%bd%aepython%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/175747.html","title":{"rendered":"Visual Studio Code\u5982\u4f55\u6b63\u786e\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27053624\/c38b94b6-6263-4d91-8c83-c4b48e8f9277.webp\" alt=\"Visual Studio Code\u5982\u4f55\u6b63\u786e\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883\" \/><\/p>\n<p><p><strong>Visual Studio Code (VS Code)\u6b63\u786e\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883<\/strong>\u9700\u8981\u5b8c\u6210\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<strong>\u5b89\u88c5Python\u6269\u5c55\u3001\u5b89\u88c5\u548c\u914d\u7f6ePython\u89e3\u91ca\u5668\u3001\u914d\u7f6elinting\u3001\u8bbe\u7f6e\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u3001\u4e3a\u8c03\u8bd5\u914d\u7f6elaunch.json\u6587\u4ef6<\/strong>\u3002\u9996\u5148\u8981\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86\u6700\u65b0\u7248\u7684Visual Studio Code\uff0c\u4ee5\u53ca\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u6709\u4e00\u4e2aPython\u89e3\u91ca\u5668\uff0c\u6bd4\u5982Python.org\u5b98\u65b9\u53d1\u5e03\u7684Python\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c<strong>\u5b89\u88c5Python\u6269\u5c55<\/strong>\u662f\u914d\u7f6e\u73af\u5883\u4e2d\u7684\u7b2c\u4e00\u6b65\u3002VS Code\u7684Python\u6269\u5c55\u63d0\u4f9b\u4e86\u5f88\u591a\u529f\u80fd\uff1a\u5982\u4ee3\u7801\u5b8c\u6210\u3001\u667a\u80fd\u63d0\u793a\u3001\u8c03\u8bd5\u652f\u6301\u7b49\uff0c\u5b83\u662fVS Code\u6210\u4e3a\u5f3a\u5927Python IDE\u7684\u5173\u952e\u7ec4\u4ef6\u3002\u5b89\u88c5\u6269\u5c55\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u6253\u5f00VS Code\u7684\u6269\u5c55\u5e02\u573a\uff0c\u641c\u7d22Python\uff0c\u7136\u540e\u9009\u62e9\u7531Microsoft\u53d1\u5e03\u7684Python\u6269\u5c55\u8fdb\u884c\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5PYTHON\u6269\u5c55<\/h3>\n<\/p>\n<p><p>\u5728VS Code\u4e2d\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883\u7684\u7b2c\u4e00\u6b65\u662f\u5b89\u88c5Python\u6269\u5c55\u3002\u8fd9\u53ef\u4ee5\u8f7b\u677e\u901a\u8fc7VS Code\u7684\u6269\u5c55\u5e02\u573a\u6765\u5b8c\u6210\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00VS Code\u3002<\/li>\n<li>\u70b9\u51fb\u5de6\u4fa7\u6d3b\u52a8\u680f\u4e2d\u7684\u6269\u5c55\u89c6\u56fe\u3002<\/li>\n<li>\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201cPython\u201d\u3002<\/li>\n<li>\u627e\u5230\u7531Microsoft\u53d1\u5e03\u7684Python\u6269\u5c55\uff0c\u5e76\u70b9\u51fb\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<p><p>\u4e00\u65e6\u5b89\u88c5\u597dPython\u6269\u5c55\uff0cVS Code\u5c31\u5df2\u5177\u5907\u4e86\u57fa\u672c\u7684Python\u652f\u6301\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b89\u88c5\u548c\u914d\u7f6ePYTHON\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u5b89\u88c5Python\u6269\u5c55\u540e\uff0c\u63a5\u4e0b\u6765\u5c31\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u5e76\u5728VS Code\u4e2d\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u4e2d\u5df2\u5b89\u88c5\u4e86Python\u3002\u4f60\u53ef\u4ee5\u4ecePython\u5b98\u7f51\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/li>\n<li>\u5728VS Code\u4e2d\uff0c\u6253\u5f00\u547d\u4ee4\u9762\u677f\uff08\u4f7f\u7528\u5feb\u6377\u952eCtrl+Shift+P\u6216Cmd+Shift+P\uff09\u3002<\/li>\n<li>\u8f93\u5165<code>Python: Select Interpreter<\/code>\u5e76\u6267\u884c\u6b64\u547d\u4ee4\u3002<\/li>\n<li>\u4ece\u5217\u8868\u4e2d\u9009\u62e9\u4e00\u4e2a\u5df2\u5b89\u88c5\u7684Python\u89e3\u91ca\u5668\u3002<\/li>\n<\/ul>\n<p><p>\u5982\u679cVS Code\u672a\u81ea\u52a8\u68c0\u6d4b\u5230Python\u89e3\u91ca\u5668\uff0c\u4f60\u53ef\u4ee5\u624b\u52a8\u6dfb\u52a0\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6eLINTING<\/h3>\n<\/p>\n<p><p>Linting\u5e2e\u52a9\u4f60\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u53d1\u73b0\u9519\u8bef\u548c\u4e0d\u89c4\u8303\u7684\u5199\u6cd5\u3002Python\u6269\u5c55\u5df2\u5185\u7f6e\u5bf9Pylint\u7684\u652f\u6301\uff0c\u4f46\u8fd8\u53ef\u4ee5\u914d\u7f6e\u5176\u4ed6\u7684linter\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728VS Code\u4e2d\uff0c\u6253\u5f00\u8bbe\u7f6e\uff08\u901a\u8fc7\u7f16\u8f91\u83dc\u5355\u4e2d\u7684\u9996\u9009\u9879\u6216\u4f7f\u7528\u5feb\u6377\u952eCtrl+,\uff09\u3002<\/li>\n<li>\u641c\u7d22<code>Python Linting<\/code>\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u542f\u7528\u6216\u7981\u7528linting\uff0c\u5e76\u4e14\u9009\u62e9\u5e0c\u671b\u4f7f\u7528\u7684linter\uff0c\u5982<code>pylint<\/code>\u3001<code>flake8<\/code>\u3001<code>mypy<\/code>\u7b49\u3002<\/li>\n<\/ul>\n<p><p><strong>\u4e3a\u4e86\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf\uff0c\u5efa\u8bae\u542f\u7528linting\u529f\u80fd<\/strong>\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u5de5\u4f5c\u533a\u8bbe\u7f6e\u4e2d\u4e3a\u4e0d\u540c\u7684\u9879\u76ee\u914d\u7f6e\u4e0d\u540c\u7684linter\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8bbe\u7f6e\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u53ef\u4ee5\u5e2e\u4f60\u81ea\u52a8\u683c\u5f0f\u5316\u4ee3\u7801\uff0c\u4fdd\u6301\u4ee3\u7801\u98ce\u683c\u4e00\u81f4\u6027\u3002VS Code\u652f\u6301\u591a\u79cd\u683c\u5f0f\u5316\u5de5\u5177\uff0c\u5982<code>autopep8<\/code>\u3001<code>black<\/code>\u548c<code>yapf<\/code>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u901a\u8fc7\u8fd0\u884c\u547d\u4ee4<code>pip install &lt;formatter name&gt;<\/code>\u6765\u5b89\u88c5\u4e00\u4e2a\u4ee3\u7801\u683c\u5f0f\u5668\uff0c\u4f8b\u5982<code>pip install black<\/code>\u3002<\/li>\n<li>\u5728VS Code\u8bbe\u7f6e\u4e2d\u641c\u7d22<code>Python Formatting<\/code>\u3002<\/li>\n<li>\u9009\u62e9\u4e00\u4e2a\u5df2\u5b89\u88c5\u7684\u683c\u5f0f\u5316\u5de5\u5177\u4f5c\u4e3a\u9ed8\u8ba4\u683c\u5f0f\u5668\uff0c\u5e76\u914d\u7f6e\u76f8\u5173\u7684\u683c\u5f0f\u5316\u9009\u9879\u3002<\/li>\n<\/ul>\n<p><p><strong>\u4f7f\u7528\u683c\u5f0f\u5316\u5de5\u5177\u662f\u4fdd\u6301\u4ee3\u7801\u6574\u6d01\u548c\u63d0\u5347\u9605\u8bfb\u4f53\u9a8c\u7684\u6709\u6548\u65b9\u6cd5<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4e3a\u8c03\u8bd5\u914d\u7f6eLAUNCH.JSON\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u91cd\u8981\u4e00\u73af\u3002\u4e3a\u4e86\u5728VS Code\u4e2d\u8c03\u8bd5Python\u4ee3\u7801\uff0c\u9700\u8981\u914d\u7f6elaunch.json\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728VS Code\u7684\u4fa7\u8fb9\u680f\u4e2d\u70b9\u51fb\u201c\u8fd0\u884c\u548c\u8c03\u8bd5\u201d\u89c6\u56fe\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u521b\u5efa launch.json \u6587\u4ef6\u201d\u6309\u94ae\u3002<\/li>\n<li>\u4ece\u5f39\u51fa\u7684\u73af\u5883\u9009\u9879\u4e2d\u9009\u62e9\u201cPython File\u201d\u3002<\/li>\n<\/ul>\n<p><p>\u8fd9\u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542bPython\u8c03\u8bd5\u914d\u7f6e\u7684launch.json\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u7f16\u8f91\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5176\u4ed6\u914d\u7f6e\u548c\u6269\u5c55<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u57fa\u672c\u914d\u7f6e\u5916\uff0c\u8fd8\u53ef\u4ee5\u5b89\u88c5\u5176\u5b83\u6709\u7528\u7684\u6269\u5c55\uff0c\u5982<code>Python Docstring Generator<\/code>\u7528\u4e8e\u751f\u6210\u6587\u6863\u5b57\u7b26\u4e32\uff0c\u6216\u8005<code>Python Test Explorer<\/code>\u7528\u4e8e\u8fd0\u884c\u6d4b\u8bd5\u5e76\u663e\u793a\u7ed3\u679c\u3002\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u5b89\u88c5\u548c\u914d\u7f6e\u8fd9\u4e9b\u6269\u5c55\u6765\u8fdb\u4e00\u6b65\u589e\u5f3aVS Code\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bed<\/h3>\n<\/p>\n<p><p>\u914d\u7f6e\u597dPython\u5f00\u53d1\u73af\u5883\u540e\uff0c\u4f60\u5c06\u5728VS Code\u4e2d\u62e5\u6709\u5f3a\u5927\u4e14\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u3002\u65e0\u8bba\u662f\u7f16\u5199\u4ee3\u7801\u3001\u6267\u884cLinting\u3001\u683c\u5f0f\u5316\u4ee3\u7801\u8fd8\u662f\u8c03\u8bd5\uff0c<strong>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684Python\u9879\u76ee\u8bbe\u7f6e\u5f97\u5f53<\/strong>\uff0c\u8ba9\u4f60\u80fd\u591f\u4e13\u6ce8\u4e8e\u4ee3\u7801\u672c\u8eab\uff0c\u800c\u51cf\u5c11\u4e0e\u73af\u5883\u8bbe\u7f6e\u76f8\u5173\u7684\u56f0\u6270\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728Visual Studio Code\u4e2d\u5b89\u88c5Python\u6269\u5c55\uff1f<\/strong><\/p>\n<p>Visual Studio Code\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u5e76\u4e0d\u81ea\u5e26Python\u652f\u6301\u3002\u8981\u5728Visual Studio Code\u4e2d\u4f7f\u7528Python\u5f00\u53d1\u73af\u5883\uff0c\u4f60\u9700\u8981\u5b89\u88c5Python\u6269\u5c55\u3002\u5728Visual Studio Code\u7684\u4fa7\u8fb9\u680f\u627e\u5230\u6269\u5c55\u56fe\u6807\uff08\u7c7b\u4f3c\u4e8e\u56db\u65b9\u5757\u7684\u56fe\u6807\uff09\uff0c\u70b9\u51fb\u540e\u641c\u7d22Python\u6269\u5c55\u5e76\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u5c06\u80fd\u591f\u5728Visual Studio Code\u4e2d\u8fd0\u884c\u548c\u8c03\u8bd5Python\u4ee3\u7801\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u914d\u7f6eVisual Studio Code\u7684Python\u89e3\u91ca\u5668\uff1f<\/strong><\/p>\n<p>\u914d\u7f6ePython\u89e3\u91ca\u5668\u662fVisual Studio Code\u4e2d\u4f7f\u7528Python\u5f00\u53d1\u73af\u5883\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6253\u5f00Visual Studio Code\u540e\uff0c\u5728\u83dc\u5355\u680f\u4e2d\u9009\u62e9\u201c\u6587\u4ef6\u201d-\u201c\u9996\u9009\u9879\u201d-\u201c\u8bbe\u7f6e\u201d\uff08\u6216\u8005\u6309Ctrl + \uff0c\uff09\uff0c\u7136\u540e\u5728\u641c\u7d22\u6846\u4e2d\u8f93\u5165\u201cpython.pythonPath\u201d\u6765\u67e5\u627ePython\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u5728\u641c\u7d22\u7ed3\u679c\u4e2d\u627e\u5230\u201cPython: Python Path\u201d\u9009\u9879\uff0c\u70b9\u51fb\u7f16\u8f91\uff0c\u8f93\u5165Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u4fdd\u5b58\u540e\u5373\u53ef\u5b8c\u6210\u914d\u7f6e\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u5728Visual Studio Code\u4e2d\u8c03\u8bd5Python\u4ee3\u7801\uff1f<\/strong><\/p>\n<p>Visual Studio Code\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u67e5\u627e\u548c\u89e3\u51b3Python\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002\u8981\u5728Visual Studio Code\u4e2d\u8c03\u8bd5Python\u4ee3\u7801\uff0c\u9996\u5148\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u70b9\u51fb\u8c03\u8bd5\u83dc\u5355\u680f\u4e0a\u7684\u201c\u5f00\u59cb\u8c03\u8bd5\u201d\u6309\u94ae\u3002\u5982\u679c\u662f\u7b2c\u4e00\u6b21\u8c03\u8bd5\uff0c\u4f60\u9700\u8981\u9009\u62e9\u8c03\u8bd5\u73af\u5883\uff08\u4f8b\u5982Python\u6587\u4ef6\u3001\u7ec8\u7aef\u7b49\uff09\u3002\u4e4b\u540e\uff0cVisual Studio Code\u5c06\u4f1a\u6309\u7167\u4f60\u8bbe\u7f6e\u7684\u65ad\u70b9\u4e00\u6b65\u6b65\u6267\u884c\u4ee3\u7801\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u63a7\u5236\u9762\u677f\u4e0a\u7684\u6309\u94ae\uff08\u4f8b\u5982\u7ee7\u7eed\u3001\u6682\u505c\u3001\u5355\u6b65\u6267\u884c\uff09\u6765\u63a7\u5236\u4ee3\u7801\u7684\u6267\u884c\u6d41\u7a0b\uff0c\u4ee5\u4fbf\u67e5\u770b\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u72b6\u6001\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Visual Studio Code (VS Code)\u6b63\u786e\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883\u9700\u8981\u5b8c\u6210\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u5b89\u88c5 [&hellip;]","protected":false},"author":3,"featured_media":175765,"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\/175747"}],"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=175747"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/175747\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/175765"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=175747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=175747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=175747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}