为什么visualstudio代码不断更改工作目录?

2024-10-03 17:17:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用VS代码来完成“flaskwebdevelopment”一书。我可以从命令行运行一个简单的helloworld示例,但是我想使用VS代码进行调试等启动.json创建烧瓶配置的文件:

    "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
    },

在哪里剥皮机.py. 是我的hello world类型应用程序的名称。每次我尝试运行或调试它时,VS都找不到该文件。我的dir结构是:

^{pr2}$

最近的pythonClass从pythonclis/a类的pythonClass学习。烧瓶目录是我目前工作的地方。 在控制台中执行pwd总是会产生pythonClass。我将cd到flasker,导出flasker应用程序=剥皮机.pyFLASK_DEBUG=1,然后FLASK运行,一切正常。但是当我尝试运行调试器时,它仍然指向pythonClass,并且找不到剥皮机.py应用程序。我在pythonClass目录中找到了一个.vscode目录,它有启动.json以及设置.json文件,但不确定它是如何/为什么在那里创建的。两个文件都没什么神奇的。我在谷歌上搜索了我能想到的每一个烧瓶cwd/pwd路径的组合。我知道这可能是个简单的解决办法,但似乎解决不了这个问题。感谢任何指导。在


Tags: 文件no代码pydebug目录json应用程序
1条回答
网友
1楼 · 发布于 2024-10-03 17:17:05

一个launch.json attributes list应该包括cwd(对于“大多数调试器”)

因此,请尝试添加一个cwd属性,其中包含所需的确切路径,以检查是否符合该路径。
例如:

"cwd": "${workspaceFolder}",

OP GeoffWillis加上in the comments

Seems odd that when doing a 'pwd' in the VScode console, it always defaults to ~/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,操作确认:

Just cd to the desired dir and type "code ." instead of just "code" seems to solve the problem.

相关问题 更多 >