[英]Debug a console_script with pycharm
I have a complex python program I'd like to debug where the setup.py has我有一个复杂的 python 程序,我想调试 setup.py 的位置
entry_points=dict(
console_scripts=[
'myprog = myprog.command:myprog_main',
]
)
where the command.py has the logic to accept command so I can run something like command.py 有接受命令的逻辑,所以我可以运行类似的东西
myprog process --config config.yaml
Placing a breakingpoint in pycharm doesn't cause the program to stop, since doing python command.py process --config config.yaml
doesn't do anything在 pycharm 中放置断点不会导致程序停止,因为执行python command.py process --config config.yaml
不会做任何事情
I feel this something basic, but I couldn't find a way to debug this (using pycharm)我觉得这是基本的,但我找不到调试方法(使用 pycharm)
Let's take jupyter notebook
as an example:我们以jupyter notebook
为例:
In jupyter
, it from jupyter_core.command import main
, so what I need to do is placing a breakpoint in jupyter_core.command:main
.在jupyter
中,它from jupyter_core.command import main
,所以我需要做的是在jupyter_core.command:main
中放置一个断点。
And then, I need to add a configuration in Pycharm.然后,我需要在 Pycharm 中添加一个配置。 Script path
should be /path/to/jupyter
, Parameters
should be notebook
. Script path
应该是/path/to/jupyter
, Parameters
应该是notebook
。
Next, I need to click Debug
.接下来,我需要单击Debug
。
I've done, I reach the breakpoint in jupyter_core.command:main
.我已经完成了,我到达了jupyter_core.command:main
的断点。
In case this answer doesn't work for you, try this:如果这个答案对你不起作用,试试这个:
add a run configuration in PyCharm在 PyCharm 中添加运行配置
configure it with Module name instead of Script path .使用Module name而不是Script path配置它。
Set the Module name to myprog.command
将模块名称设置为myprog.command
Add the following section to myprog/command.py
:将以下部分添加到myprog/command.py
:
if __name__ == "__main__": myprog_main()
Sadly, setting the Module name to myprog.command:myprog_main
doesn't work.可悲的是,将模块名称设置为myprog.command:myprog_main
不起作用。
Set the Working directory to the root of your repo (ie the parent of the module myprog
such that the imports work).将工作目录设置为您的存储库的根目录(即模块myprog
的父级,以便导入工作)。
Note : I used the exact names from OP's question.注意:我使用了 OP 问题中的确切名称。 Please adjust the names of functions, modules, and packages for your problem accordingly.请根据您的问题相应地调整函数、模块和包的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.