gpt4 book ai didi

python - VS Code - 在模块模式下为 console_script 运行调试配置

转载 作者:行者123 更新时间:2023-12-04 12:59:02 29 4
gpt4 key购买 nike

我的 setup.py有以下 console_scripts 作为入口点:

entry_points={
'console_scripts': ['script=myapp.app:do_something',
'script2=myapp.app:do_something2'],
},


具有以下结构
.
├── myapp
│ ├── __init__.py
│ ├── app.py
│ ├── mod.py
│ ├── mod2.py
│ └── submodules
│ ├── __init__.py
│ └── mod3.py
├── requirements.txt
└── setup.py

和应用程序看起来像
##my_app.app

def do_something():
#do stuff
def do_something2():
#do other stuff


如何获取 VS 代码调试配置以输入这些模块属性。如果我使用 if __name__ == "__main__": do_something(),我可以运行该模块但希望根据 console_scripts 使用单独的 launch.json 文件
##launch.json
{
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "myapp.app",
"args": ["--hello world"]
}
]
}

认为你可以做类似的事情:
  "module": "myapp.app:do_something",

可惜:
No module named myapp.app:do_something

最佳答案

目前没有办法使这项工作。每个入口点至少需要一个单独的模块,或者有一个接受命令行参数的模块,然后选择要调用的函数。

关于python - VS Code - 在模块模式下为 console_script 运行调试配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61693769/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com