为什么Visual Studio Code不断更改工作目录? [英] Why does Visual Studio Code keep changing the working directory?
问题描述
我正在尝试使用VS Code来完成"Flask Web开发"这本书.我可以从命令行运行一个简单的hello world示例,但我想使用VS代码进行调试等.我修改了launch.json文件以构建Flask配置:
I am trying to use VS Code to work my way through the "Flask Web Development" book. I can get the simple hello world example running from the command line but I want to use VS code for debugging etc. I modify the launch.json file to build a Flask config:
"name": "Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "flasker.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
其中flasker.py.是我的世界类型应用程序的名称.每次我尝试运行或调试它时,VS都找不到该文件.我的目录结构是:
where flasker.py. is the name of my hello world type app. Every time I try to run it, or debug it, VS can not find the file. My dir structure is:
dev
--pythonStuff
--pythonClass
--flask
flasker.py
pythonClass是我最近学习的python类的目录/游乐场.Flask目录是我目前正在使用的目录.在控制台中执行pwd总是会产生pythonClass.我将转到cd播放器,导出FLASK_APP = flasker.py和FLASK_DEBUG = 1,然后运行flask,一切都很好.但是,当我尝试运行调试器时,它仍然指向pythonClass,并且找不到flasker.py应用程序.我确实在pythonClass目录中找到一个.vscode目录,该目录具有launch.json和settings.json文件,但不确定如何/为什么在此创建它.在这两个文件中都没有什么神奇的东西.我用谷歌搜索了我能想到的烧瓶cwd/pwd PATH的每种组合.我知道这可能是一个简单的修复程序,但似乎无法解决这个问题.感谢任何指导.
pythonClass is a dir/playground from a recent python class I took. The flask dir is where I'm currently working. Doing a pwd in the console always yields pythonClass. I'll cd to flasker, export FLASK_APP=flasker.py and FLASK_DEBUG=1 and then flask run and everything is good. But when I try to run the debugger, it's still pointing to pythonClass and can't find the flasker.py app. I did find a .vscode dir in the pythonClass dir, which has launch.json and settings.json files, but not sure how/why it was created there. Nothing magical in either file. I've googled every combination of flask cwd/pwd PATH I can think of. I know it's probably a simple fix, but can't seem to sort this out. Appreciate any guidance.
推荐答案
一个launch.json属性列表应该包含 cwd
(用于大多数调试器")
A launch.json attributes list is supposed to include cwd
(for "most debugger")
因此,尝试添加具有所需确切路径的 cwd
属性,以检查是否遵守该规定.
例如:
So try and add a cwd
attributes, with the exact path you want, to check if that is respected.
For instance:
"cwd": "${workspaceFolder}",
OP GeoffWillis 添加了 似乎很奇怪,即使在VScode控制台中执行"pwd"操作时,即使我使用"code"别名从"flask"目录中启动VScode,它始终默认为 Seems odd that when doing a 'pwd' in the VScode console, it always defaults to 我建议使用最小的 I suggesting using a minimal 只需 Just 这篇关于为什么Visual Studio Code不断更改工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!〜/pythonStuff/pythonClass
.
如前所述,我可以在控制台中 cd
到我的烧瓶目录,然后运行代码就可以了,但是需要调试器.
我在新的Mac book pro上使用OSX 10.13.6,我先安装了VScode,然后又安装了Anaconda(包括VScode).也许他们互相踩踏了吗?
~/pythonStuff/pythonClass
even if I launch VScode from my "flasky" directory using the "code" alias.
As stated, I can cd
in the console to my flasky dir, and run the code just fine, but want the debugger.
I'm using OSX 10.13.6 on a newish Mac book pro, and I installed VScode, then installed Anaconda (With VScode included). Maybe they're stepping on each other? PATH
,然后OP确认:PATH
, and the OP confirms: cd
到所需目录,然后键入" code.
",而不只是" code
"即可解决此问题.
cd
to the desired dir and type "code .
" instead of just "code
" seems to solve the problem.