{"id":5054,"date":"2022-04-15T10:15:01","date_gmt":"2022-04-15T02:15:01","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=5054"},"modified":"2024-05-05T14:19:06","modified_gmt":"2024-05-05T06:19:06","slug":"vscode-python-%e8%99%9a%e6%8b%9f%e7%8e%af%e5%a2%83%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=5054","title":{"rendered":"vscode + Python \u865a\u62df\u73af\u5883\u5f00\u53d1"},"content":{"rendered":"\n<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u53ef\u80fd\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u67d0\u4e2a\u7248\u672c\u53f7\u7684\u8f6f\u4ef6\uff0c\u53e6\u5916\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u53e6\u5916\u4e00\u4e2a\u7248\u672c\u53f7\u7684\u5e93\uff0c\u5982\u679c\u76f4\u63a5\u5728\u7cfb\u7edf\u73af\u5883\u4e2d\u914d\u7f6e\u5e93\u73af\u5883\uff0c\u662f\u4e0d\u53ef\u80fd\u540c\u65f6\u5171\u5b58\u4e00\u4e2a\u5e93\u7684\u591a\u4e2a\u7248\u672c\u7684\u3002\u53e6\u5916\u76f4\u63a5\u5728\u7cfb\u7edf\u4e2d\u6dfb\u52a0\u5e93\uff0c\u5f88\u53ef\u80fd\u7834\u574f\u4f9d\u8d56\u5173\u7cfb\uff0c\u7cfb\u7edf\u672c\u8eab\u4e5f\u6709\u8f6f\u4ef6\u4f9d\u8d56 Python \u7684\uff0c\u5e93\u4f9d\u8d56\u5173\u7cfb\u7834\u574f\u6709\u65f6\u5019\u53ef\u80fd\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u3002\u56e0\u6b64\u53ef\u4ee5\u91c7\u7528\u865a\u62df\u73af\u5883\uff0c\u5f53\u8981\u8fdb\u884c\u4e00\u4e2a\u9879\u76ee\u7684\u65f6\u5019\uff0c\u5c31\u4e13\u95e8\u4e3a\u5b83\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u5728\u91cc\u9762\u6dfb\u52a0\u9879\u76ee\u6240\u9700\u8981\u7684\u5e93\uff0c\u9879\u76ee\u5c31\u4f7f\u7528\u8fd9\u4e2a\u865a\u62df\u73af\u5883\u5185\u7684\u5e93\uff0c\u800c\u865a\u62df\u73af\u5883\u4e0d\u4f1a\u5f71\u54cd\u5230\u7cfb\u7edf\u7684\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u6ce8\u610f\u4e00\u70b9\uff0cWindows \u4e0b\u5b89\u88c5 Python3 \u540e\uff0c\u5bf9\u5e94 python \u547d\u4ee4\u5bf9\u5e94\u7684\u5c31\u662f Python3\u3002\u800c\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38\u8981\u660e\u786e\u6307\u660e\uff0c\u5728\u65e7\u4e00\u4e9b\u7684\u7cfb\u7edf\u4e2d\u57fa\u672c\u90fd\u662f\u9884\u88c5\u4e86 Python2 \u7684\uff0c\u800c python \u547d\u4ee4\u5bf9\u5e94\u7684\u5c31\u662f Python2\uff0c\u5982\u679c\u8981\u4f7f\u7528 Python3\uff0c\u90a3\u4e48\u547d\u4ee4\u5c31\u662f python3\u3002\u800c\u5728\u6700\u65b0\u7684\u7cfb\u7edf\u4e2d\uff0c\u6bd4\u5982\u8fd9\u91cc\u6211\u662f\u7528\u7684\u6811\u8393\u6d3e\u8fdb\u884c\u6f14\u793a\uff0c\u91cc\u9762\u7684\u7cfb\u7edf\u5237\u7684\u4eca\u5e74\u7684\u65b0\u7248\uff0c\u57fa\u4e8e Debian 11 \u7684\u5b9a\u5236\u7248\uff0c\u91cc\u9762\u7ec8\u4e8e\u4e0d\u518d\u9884\u88c5 Python2 \u4e86\uff0cpython \u547d\u4ee4\u5bf9\u5e94\u7684\u5c31\u662f Python3\u3002\u540c\u6837 pip \u548c pip3 \u4e5f\u662f\u8fd9\u6837\u7684\u5bf9\u5e94\u5173\u7cfb\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u6a21\u5757\u4e5f\u633a\u591a\u7684\uff0c\u6211\u4f7f\u7528\u7684\u662f Python \u5185\u7f6e\u7684 venv\u3002\u56e0\u4e3a\u8fd9\u91cc\u6211\u662f\u5728 Linux \u4e0b\u6f14\u793a\u7684\uff0c\u6240\u4ee5\u547d\u4ee4\u7528\u7684 python3 \uff0c\u5982\u679c\u662f\u5728 Windows \u4e0b\u5c31\u8981\u7528 python\uff0c\u5176\u5b83\u64cd\u4f5c\u90fd\u662f\u901a\u7528\u7684\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u4f7f\u7528\u6b65\u9aa4<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u5bf9\u4e8e Linux \u4e0b\uff0c\u5982\u679c\u662f\u7f16\u8bd1\u5b89\u88c5\u7684 Python\uff0c\u5e94\u8be5\u5df2\u7ecf\u5305\u542b\u4e86venv \u6a21\u5757\n# \u5982\u679c\u662f\u7528\u7684\u9884\u88c5\u7684 Python\uff0c\u5219\u53ef\u80fd\u6ca1\u6709\u9884\u88c5\uff0c\u4f7f\u7528\u547d\u4ee4 sudo apt install python3-venv \u8fdb\u884c\u5b89\u88c5\n\n# \u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\npython3 -m venv \u3010\u9879\u76ee\u6587\u4ef6\u5939\u540d\u3011\n\n# \u8fdb\u5165\u865a\u62df\u73af\u5883\nsource \u3010\u9879\u76ee\u6587\u4ef6\u5939\u540d\u3011\/bin\/activate\n\n# \u7136\u540e\u8fd9\u4e2a\u4f7f\u7528\u7528 pip \u5b89\u88c5\u7684\u5e93\u5c31\u662f\u653e\u5230\u865a\u62df\u73af\u5883\u91cc\u4e86\n\n# \u9000\u51fa\u865a\u62df\u73af\u5883\ndeactivate<\/pre>\n\n\n\n<p>\u4f46\u662f\u5f00\u53d1\u4e2d\uff0c\u4e00\u822c\u8981\u7ed3\u5408\u8c03\u8bd5\uff0c\u4e0d\u662f\u5355\u7eaf\u8fd9\u6837\u4f7f\u7528\u3002\u8fd9\u91cc\u53ef\u4ee5\u914d\u5408 vscode\uff0c\u8ba9 vscode \u8fdb\u5165\u865a\u62df\u73af\u5883\uff0c\u8fdb\u884c\u5f00\u53d1\u3002\u4e0b\u9762\u5c31\u8bb0\u5f55\u4e86\u4e00\u4e2a\u64cd\u4f5c\u8fc7\u7a0b\u4ee5\u4f5c\u53c2\u8003\uff1a<\/p>\n\n\n\n<p>\u9996\u5148\u6253\u5f00\u7ec8\u7aef\uff0c\u6211\u5728\u5bb6\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a test \u7684\u9879\u76ee<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python3 -m venv ~\/test<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"275\" height=\"68\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-185.png\" alt=\"\" class=\"wp-image-5056 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 275px; --smush-placeholder-aspect-ratio: 275\/68;\" \/><\/figure>\n\n\n\n<p>\u7136\u540e vscode \u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\u5939<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"778\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-186-1024x778.png\" alt=\"\" class=\"wp-image-5057 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-186-1024x778.png 1024w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-186-300x228.png 300w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-186-768x583.png 768w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-186.png 1035w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/778;\" \/><\/figure>\n\n\n\n<p>\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5 Python \u63d2\u4ef6 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"564\" height=\"194\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-188.png\" alt=\"\" class=\"wp-image-5059 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-188.png 564w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-188-300x103.png 300w\" data-sizes=\"(max-width: 564px) 100vw, 564px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 564px; --smush-placeholder-aspect-ratio: 564\/194;\" \/><\/figure>\n\n\n\n<p>\u6309 Ctrl+Shift+P \uff0c\u7136\u540e\u641c\u7d22 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">python select interpreter<\/mark>\uff0c\u5e76\u70b9\u51fb\u9009\u62e9\u89e3\u91ca\u5668<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"650\" height=\"142\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-187.png\" alt=\"\" class=\"wp-image-5058 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-187.png 650w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-187-300x66.png 300w\" data-sizes=\"(max-width: 650px) 100vw, 650px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 650px; --smush-placeholder-aspect-ratio: 650\/142;\" \/><\/figure>\n\n\n\n<p>\u70b9\u51fb\u8f93\u5165\u89e3\u91ca\u5668\u8def\u5f84\uff0c\u7136\u540e\u70b9\u51fb\u6d4f\u89c8<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"362\" height=\"156\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-190.png\" alt=\"\" class=\"wp-image-5061 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-190.png 362w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-190-300x129.png 300w\" data-sizes=\"(max-width: 362px) 100vw, 362px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 362px; --smush-placeholder-aspect-ratio: 362\/156;\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"346\" height=\"97\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-191.png\" alt=\"\" class=\"wp-image-5062 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-191.png 346w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-191-300x84.png 300w\" data-sizes=\"(max-width: 346px) 100vw, 346px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 346px; --smush-placeholder-aspect-ratio: 346\/97;\" \/><\/figure>\n\n\n\n<p>\u9009\u62e9\u9879\u76ee\u76ee\u5f55 bin \u4e4b\u4e0b\u7684 python3<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"604\" height=\"214\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-196.png\" alt=\"\" class=\"wp-image-5067 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-196.png 604w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-196-300x106.png 300w\" data-sizes=\"(max-width: 604px) 100vw, 604px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 604px; --smush-placeholder-aspect-ratio: 604\/214;\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"620\" height=\"312\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-197.png\" alt=\"\" class=\"wp-image-5068 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-197.png 620w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-197-300x151.png 300w\" data-sizes=\"(max-width: 620px) 100vw, 620px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 620px; --smush-placeholder-aspect-ratio: 620\/312;\" \/><\/figure>\n\n\n\n<p>\u6b64\u65f6 vscode \u5c31\u8fdb\u5165\u4e86\u865a\u62df\u73af\u5883\u4e2d\uff0c\u7a0b\u5e8f\u8c03\u8bd5\u8fd0\u884c\u4f7f\u7528\u7684\u4e5f\u662f\u865a\u62df\u73af\u5883\u4e2d\u7684\u5e93\u3002<\/p>\n\n\n\n<p>\u6253\u5f00\u4e00\u4e2a\u65b0\u7ec8\u7aef\uff0c\u6b64\u65f6\u4f1a\u5e26\u4e0a\u865a\u62df\u73af\u5883\u7684\u540d\u5b57\uff0c\u8bf4\u660e\u5904\u4e8e\u865a\u62df\u73af\u5883\u4e2d<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"506\" height=\"237\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-198.png\" alt=\"\" class=\"wp-image-5069 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-198.png 506w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-198-300x141.png 300w\" data-sizes=\"(max-width: 506px) 100vw, 506px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 506px; --smush-placeholder-aspect-ratio: 506\/237;\" \/><\/figure>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u4ee3\u7801\u6587\u4ef6\u5e76\u6253\u5f00\u65f6\uff0c\u53f3\u4e0b\u89d2\u83dc\u5355\u4e5f\u4f1a\u663e\u793a\u5f53\u524d\u7684 Python \u73af\u5883<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"772\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-199-1024x772.png\" alt=\"\" class=\"wp-image-5070 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-199-1024x772.png 1024w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-199-300x226.png 300w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-199-768x579.png 768w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/04\/image-199.png 1046w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/772;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u53ef\u80fd\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u67d0\u4e2a\u7248\u672c\u53f7\u7684\u8f6f\u4ef6\uff0c\u53e6\u5916\u4e00\u4e2a\u9879\u76ee\u9700\u8981\u53e6\u5916\u4e00\u4e2a\u7248\u672c\u53f7\u7684\u5e93\uff0c\u5982\u679c\u76f4\u63a5\u5728\u7cfb\u7edf\u73af\u5883\u4e2d\u914d\u7f6e\u5e93\u73af\u5883 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-5054","post","type-post","status-publish","format-standard","hentry","category-all"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/5054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5054"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/5054\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}