如何在调试下运行Python程序并设置运行的工作目录?
当前回答
这个设置帮助我:(我是一个Windows用户)
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"cwd": "${workspaceFolder}\\app\\js", // set directory here
"program": "${workspaceFolder}\\app\\js\\server.js", // set start js here
}
其他回答
这个设置帮助我:(我是一个Windows用户)
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"cwd": "${workspaceFolder}\\app\\js", // set directory here
"program": "${workspaceFolder}\\app\\js\\server.js", // set start js here
}
你可以在launch.json中使用cwd参数设置调试程序的当前工作目录
我也遇到了同样的问题,并注意到当在Mac的终端中运行which python命令时,它会显示与我在vs code中运行which python命令时所得到的路径不同。并且当使用python filename.py运行时,我的文件在终端中正常运行
所以我从终端复制了该路径,并将其粘贴到VS代码中的首选项->设置->扩展->Python->默认解释器路径,它工作了。我希望这能有所帮助。
我使用“justMyCode = false”,所以我也可以调试和跳转到主脚本调用的函数。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${fileDirname}" }
]
}
设置当前工作目录为当前正在执行的文件:
File > Preferences > Settings > Python > Data Science >在File Dir执行
brch: Python in VSCode:每次设置工作目录为Python文件的路径
推荐文章
- 如何排序mongodb与pymongo
- 不可变与可变类型
- 列表是线程安全的吗?
- 操作系统。makdirs在我的路径上不理解“~”
- 如何在Django模板中获得我的网站的域名?
- 在django Forms中定义css类
- 如何在Python中scp ?
- 如何在Visual Studio代码中触发参数提示?
- Numpy Max vs amax vs maximum
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 每n行有熊猫
- 实例属性attribute_name定义在__init__之外
- 如何获取在Python中捕获的异常的名称?
- 第一次出现的值大于现有值的Numpy
- 如何从Python函数中返回两个值?