{"id":438279,"date":"2021-04-19T00:07:04","date_gmt":"2021-04-18T16:07:04","guid":{"rendered":"http:\/\/4563.org\/?p=438279"},"modified":"2021-04-19T00:07:04","modified_gmt":"2021-04-18T16:07:04","slug":"%e6%b1%82%e5%8a%a9-vs-code-%e5%a6%82%e4%bd%95%e8%87%aa%e5%8a%a8%e5%8a%a0%e8%bd%bd-pythonpath-%e7%ad%89%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f-%e5%b7%b2%e5%96%84%e7%94%a8%e6%90%9c%e7%b4%a2","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=438279","title":{"rendered":"[\u6c42\u52a9] VS Code \u5982\u4f55\u81ea\u52a8\u52a0\u8f7d PYTHONPATH \u7b49\u73af\u5883\u53d8\u91cf [\u5df2\u5584\u7528\u641c\u7d22]"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  [\u6c42\u52a9] VS Code \u5982\u4f55\u81ea\u52a8\u52a0\u8f7d PYTHONPATH \u7b49\u73af\u5883\u53d8\u91cf [\u5df2\u5584\u7528\u641c\u7d22]               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leverestfish <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u7528 vscode \u5199 python \u611f\u89c9\u5305\u8def\u5f84\u641c\u7d22\u6709\u70b9\u8188\u5e94\uff0c\u6545\u6765\u6b64\u8be2\u95ee\u3002<\/p>\n<p>[\u9700\u6c42] \u81ea\u52a8\u52a0\u8f7d src \u7b49 content root \u76ee\u5f55\u5230\u641c\u7d22\u76ee\u5f55\uff0c\u4e0d\u60f3\u6bcf\u6b21\u6253\u5f00 vscode \u5728\u547d\u4ee4\u884c\u624b\u52a8\u8f93<code>export pythonpath = ...<\/code><\/p>\n<p>[\u6210\u679c] \u76ee\u524d\u63a2\u7d22\u6210\u679c\uff1a<\/p>\n<ul>\n<li> \u5b9e\u73b0 vscode \u89e3\u6790\u4ee3\u7801\uff08\u81ea\u52a8\u8865\u5168\u7b49\uff09\u7684\u641c\u7d22\u8def\u5f84\n<ul>\n<li>\u901a\u8fc7 setting.json \u7684<code>\"python.envFile\"<\/code>\u5b57\u6bb5\u4ee5\u53ca<code>.env<\/code>\u6587\u4ef6<\/li>\n<\/ul>\n<\/li>\n<li> \u5b9e\u73b0 debug \u6a21\u5f0f run\n<ul>\n<li>\u901a\u8fc7 lauch.json \u7684<code>\"python.envFile\"<\/code>\u5b57\u6bb5\u4ee5\u53ca<code>.env<\/code>\u6587\u4ef6<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>[\u95ee\u9898] \u6240\u4ee5 vscode \u53f3\u4e0a\u89d2\u90a3\u4e2a\u4e09\u89d2\u5f62 run \u6309\u94ae\uff08 run python with termianl \uff09\u89e6\u53d1\u7684\u4ee3\u7801\u8fd0\u884c\u5982\u4f55\u624d\u80fd\u52a0\u8f7d.env<\/p>\n<p>\u8fd9\u4e2a\u4e09\u89d2\u5f62 run \u5e94\u8be5\u662f python extension \u5305\u5e26\u7684\uff0c\u4e0d\u77e5\u9053\u54ea\u91cc\u80fd\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<p>\u53e6\u5916\u95ee\u4e00\u4e0b\uff0c\u4e3a\u4ec0\u4e48 vscode \u7684 python \u5957\u4ef6\uff0c\u8fde <code>if name == main<\/code> \u8fd9\u79cd\u5e38\u7528 snippet \u90fd\u4e0d\u80fd\u8865\u5168\u51fa\u6765<\/p>\n<p>[\u73af\u5883] macOS \u63d2\u4ef6\u7684\u8bdd python \u76f8\u5173\u5c31\u662f vscode \u63a8\u8350\u7684\u90a3\u5957 extension pack<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>11<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5749728\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ch2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u9700\u8981\u7684\u529f\u80fd\u592a\u591a\u4e86\u7684\u8bdd\uff0c\u8fd8\u662f ptcharm \u66f4\u5408\u9002\uff0cvscode \u5bf9 python \u4ec5\u9650\u4e8e\u8f7b\u5ea6\u7f16\u8f91                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749729\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : geelaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u4ee5\u7528 .vscofe\/settings.json \u6539\u53d8\u6253\u5f00\u6a21\u62df\u7ec8\u7aef\u65f6\u4f7f\u7528\u7684 shell \u547d\u4ee4\uff08\u52a0\u5165\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7684\u5b9e\u53c2\uff09\uff0c\u4f46\u6211\u4e0d\u77e5\u9053\u8fd9\u5bf9\u64ad\u653e\u6309\u94ae\u662f\u5426\u6709\u6548\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749730\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SenLief <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             vscode \u4e0d\u662f ide\uff0c\u4ed6\u53ea\u662f\u7f16\u8f91\u5668\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749731\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aladdindingding <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e48\u8bf4\u5427 Pycharm \u89e3\u541b\u6101\uff0c\u6211\u4e5f\u662f vscode \u88ab\u8feb\u8f6c\u7684\uff0cvscode \u62ff\u6765\u770b\u770b\u6e90\u7801\uff0c\u8bfb\u4e0b\u4ee3\u7801\u8fd8\u662f\u4e0d\u9519\u7684\uff0c\u5e72\u6d3b\u8fd8\u5f97 Pycharm                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749732\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : leverestfish <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ch2 \u6211\u4e3b\u529b\u5c31\u662f\u4f7f\u7528 pycharm \u7684\uff0c\u800c\u4e14\u6b63\u662f\u8fd9\u4e2a\u539f\u56e0\u4f7f\u5f97\u6211\u5bf9 pycharm \u7684\u81ea\u52a8\u52a0\u8f7d pythonpath \u6709\u4f9d\u8d56\u3002\u4f46\u662f\u6709\u7684\u573a\u666f\uff08\u6bd4\u5982\u9700\u8981\u8fdc\u7a0b\u8fde\u5f00\u53d1\u673a\uff08 pycharm \u4e5f\u53ef\u4ee5 remote ssh \u4f46\u662f\u672c\u8d28\u4e0d\u592a\u4e00\u6837\uff09\uff09\uff0c\u8fd9\u65f6\u5019\u56e0\u4e3a\u6211\u6ca1\u5199 sys.path.append \u4e4b\u7c7b\u7684\uff0c\u6240\u4ee5\u5c31\u5f88\u4e0d\u65b9\u4fbf\u4e86\u3002<\/p>\n<p>@geelaw \u6210\u529f\u4e86\uff0csetting \u914d\u7f6e\u5982\u4e0b\u3002<\/p>\n<p>&#8220;` JSON<br \/>{<br \/> &#8220;terminal.integrated.env.osx&#8221;: {<br \/> &#8220;PYTHONPATH&#8221;: &#8220;$PYTHONPATH:&lt;MYPATH&gt;&#8221;<br \/> }<br \/>}<br \/>&#8220;`<\/p>\n<p>\u4f46\u662f\u6709\u4e2a\u5c0f bug\uff0c\u5f53\u6211\u6ca1\u6709\u6253\u5f00\u4efb\u4f55\u7ec8\u7aef\u7684\u65f6\u5019\uff0c\u70b9\u64ad\u653e\u6309\u94ae\u4f1a\u63d0\u793a`Command python.execInTerminal-icon not found`                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749733\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5443 \u5176\u4ed6\u7684\u4f60\u89e3\u51b3\u4e86, \u90a3\u6211\u5c31\u63d0\u4e00\u4e0b main \u7684\u4ee3\u7801\u7247\u6bb5\u4e0d\u80fd\u8865\u5168\u7684\u95ee\u9898, \u8fd9\u4e2a\u5c31\u4e0d\u662f\u5584\u7528\u641c\u7d22\u80fd\u89e3\u51b3\u7684\u4e86, \u56e0\u4e3a\u4e0d\u662f bug, \u53ef\u4ee5\u53c2\u8003\u6211\u4e4b\u524d\u53d1\u8fc7\u7684\u5e16\u5b50, \u5f53\u65f6\u627e\u4e86 2 \u5929, \u7ed3\u679c\u4ece\u66f4\u65b0\u65e5\u5fd7\u91cc\u627e\u5230\u7684, \u5751, \u4e71\u8c03\u9ed8\u8ba4\u8bbe\u7f6e\u592a\u90c1\u95f7\u4e86.<\/p>\n<p>VSCode 6 \u5929\u524d\u66f4\u65b0\u4e86 Python \u6269\u5c55, \u9ed8\u8ba4\u4e0d\u5e26\u4ee3\u7801\u7247\u6bb5, \u4e0d\u662f\u81ea\u52a8\u8865\u5168\u574f\u4e86, \u671b\u5468\u77e5 &#8211; V2EX &#8211; https:\/\/www.v2ex.com\/t\/749066#reply7                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749734\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : leverestfish <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ClericPy \u975e\u5e38\u611f\u8c22\uff01\uff01\uff01\uff01\uff01\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749735\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : leverestfish <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ClericPy \u987a\u4fbf\u95ee\u4e0b\uff0c\u5982\u4f55\u8bb2 Snippets \u7f6e\u9876\uff0c\u6216\u8005\u662f\u8c03\u6574\u8865\u5168\u9009\u9879\u7684\u51fa\u73b0\u987a\u5e8f\uff1f\u4ee5\u53ca\u80fd\u5426 disable \u8865\u5168\u63d2\u4ef6\u81ea\u5e26\u7684\u4e00\u4e9b\u9009\u9879\uff0c\u6bd4\u5982 if for \u4e4b\u7c7b\u7684\uff08\u6ca1\u6709\u6269\u5c55\u7684\u5751\u4f4d\u5b8c\u5168\u6ca1\u7528\u554a\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749736\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @leverestfish <br \/>\u987a\u5e8f\u7684\u95ee\u9898\u8fd8\u771f\u6ca1\u6ce8\u610f\u8fc7&#8230; \u6211\u628a\u4e0d\u7528\u7684\u90a3\u51e0\u4e2a\u90fd\u5220\u4e86, \u6269\u5c55\u7684\u8bdd, \u6211\u4e5f\u6ca1\u5565\u5176\u4ed6\u8865\u5168\u6269\u5c55, \u4e00\u5f00\u59cb\u7528 jedi, \u540e\u6765 lsp \u771f\u9999\u771f\u5feb, \u540e\u6765 lsp \u592a\u5403\u5185\u5b58\u4e86\u6362\u5230 pylance \u4e0a(\u73b0\u5728\u5c31\u662f\u6bcf\u6b21\u67e5\u770b\u5b9a\u4e49\u9ed8\u8ba4\u662f pyi \u5f88\u70e6)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749737\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : generated <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53c2\u8003\u914d\u7f6e<br \/>{<br \/> &#8220;python.pythonPath&#8221;: &#8220;venv\/Scripts\/python.exe&#8221;,<br \/> &#8220;python.analysis.extraPaths&#8221;: [<br \/> &#8220;\/your_extra_pythonpath&#8221;<br \/> ],<br \/> &#8220;python.autoComplete.extraPaths&#8221;: [<br \/> &#8220;\/your_extra_pythonpath&#8221;<br \/> ],<br \/> &#8220;files.watcherExclude&#8221;: {<br \/> &#8220;**\/.git\/objects\/**&#8221;: true,<br \/> &#8220;**\/.git\/subtree-cache\/**&#8221;: true,<br \/> &#8220;**\/node_modules\/*\/**&#8221;: true,<br \/> &#8220;**\/.hg\/store\/**&#8221;: true,<br \/> &#8220;**\/venv\/**&#8221;: true<br \/> },<br \/> &#8220;search.exclude&#8221;: {<br \/> &#8220;**\/node_modules&#8221;: true,<br \/> &#8220;**\/bower_components&#8221;: true,<br \/> &#8220;**\/venv\/**&#8221;: true,<br \/> &#8220;**\/.git\/**&#8221;: true,<br \/> }<br \/>}<\/p>\n<p>\u5c06\u4f60\u9700\u8981\u8865\u5168\u7684\u76ee\u5f55\u52a0\u5230 &#8220;python.autoComplete.extraPaths&#8221; \u548c &#8220;python.analysis.extraPaths&#8221; \u4e2d\u5c31\u53ef\u4ee5\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5749738\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : leverestfish <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @generated \u89e3\u6790\u548c\u81ea\u52a8\u8865\u5168\u6211\u901a\u8fc7 python.envFile \u89e3\u51b3\u4e86\uff0c\u4f46\u662f\u4f60\u8fd9 setting \u597d\u50cf\u6ca1\u6709\u89e3\u51b3\u8fd0\u884c\u65f6 pythonpath                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u6c42\u52a9] VS Code \u5982\u4f55\u81ea\u52a8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/438279"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=438279"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/438279\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=438279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=438279"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=438279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}