简体   繁体   English

如何调试由 pip 安装的工具?

[英]How can I debug a tool that is installed by pip?

I have a tool installed by the command pip install.我有一个通过命令 pip install 安装的工具。

However, I would like to use a debugger to go through its execution flow.但是,我想使用调试器来完成其执行流程。

I know for debugging what usually happens is attach pdb in command line.我知道调试通常发生的事情是在命令行中附加 pdb。 like python3 -m pdb [some args]python3 -m pdb [some args]

But the tool is working like this tool [some args]但是这个工具就像这个tool [some args]一样工作tool [some args]

How can attach a debugger to this?如何将调试器附加到此?

On Linux in console/terminal you can use在控制台/终端中的 Linux 上,您可以使用

which tool

to get /full/path/to/tool获取/full/path/to/tool

and then you can run然后你可以运行

python3 -m pdb /full/path/to/tool [some args]

You can also use /full/path/to/tool to open it in text editor and see source code, and add some code for debuging.您也可以使用/full/path/to/tool在文本编辑器中打开它并查看源代码,并添加一些用于调试的代码。


On Windows should be similar function to find full path to tool and then you can do the same.在 Windows 上应该有类似的功能来找到tool完整路径,然后你可以做同样的事情。


If you can import tool in Python then you can also use print( tool.__file__ ) to get /full/path/to/tool如果您可以在 Python 中import tool ,那么您也可以使用print( tool.__file__ ) 来获取/full/path/to/tool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM