简体   繁体   English

如何在python *.py之前使用命令在pycharm中进行调试?

[英]how to debug in pycharm with command before python *.py?

I am trying to debug the code in corporate server, however, I need to get permission by using a sepcific command(make it short, I'll call it p ).我正在尝试调试公司服务器中的代码,但是,我需要使用 sepcific 命令获得许可(简短一点,我将其称为p )。 How could I debug in pycharm with a start command如何使用启动命令在 pycharm 中进行调试

p python main.py

I tried to edit configuration, but neither parameters nor interpreter options worked as I expected.我试图编辑配置,但参数和解释器选项都没有按我预期的那样工作。 Are there any settings can modify the command to start python?有什么设置可以修改启动python的命令吗?

The ability of showing value of variable using pdb just not satisfy my requirements.使用pdb显示变量值的能力不能满足我的要求。

This worked for me on macOS 11. Since I don't know what p in your question is, I used the time command for testing:这在 macOS 11 上对我有用。由于我不知道您问题中的p是什么,我使用time命令进行测试:

Created a shell script named /var/tmp/python and made it an executable ( chmod +x /var/tmp/python ):创建了一个名为/var/tmp/python的 shell 脚本并使其成为可执行文件 ( chmod +x /var/tmp/python ):

#!/bin/sh
time /usr/bin/python3 "$@"

The "$@" is used to pass all command line arguments passed to /var/tmp/python to the actual /usr/bin/python3 . "$@"用于将传递给/var/tmp/python所有命令行参数传递给实际的/usr/bin/python3

Then I added a new System Interpreter in PyCharm and picked /var/tmp/python as the executable.然后我在 PyCharm 中添加了一个新的系统解释器并选择/var/tmp/python作为可执行文件。

When I debug my "Hello world" application this is the output:当我调试我的“Hello world”应用程序时,这是输出:

/var/tmp/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 53332 --file "/var/tmp/hello_world.py"
Connected to pydev debugger (build 212.5457.59)
Hello, world!

real    0m3.091s
user    0m0.292s
sys 0m0.078s

Process finished with exit code 0

as you can see in addition to executing/debugging the application it also printed the total time passed.正如您所看到的,除了执行/调试应用程序之外,它还打印了经过的总时间。

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

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