我现在面临的问题:
有没有办法如何以特定用户的身份运行/调试脚本(比如sudo su - user)?
我已经阅读过如何在PyCharm的远程/调试配置中指定一些Python Interpeter选项,但没有设法获得可行的解决方案。
答案 0 :(得分:8)
If you want an easy and more flexible way to get into the PyCharm debugger, rather than necessarily having a one-click "play" button in PyCharm, you can use the debug server functionality. I've used this in situations where running some Python code isn't as simple as running python ...
.
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
/Applications/PyCharm.app/Contents/debug-eggs
)Edit configurations...
, hit the +
button, choose Python remote debug
.
Local host name
to your laptop's IP addressport
to any free port that you can use on your laptop (e.g. 8888
)import
and pydevd.settrace(...)
statements into your code, specifically where you want your code to "hit a breakpoint". This is basically the PyCharm equivalent of import pdb; pdb.set_trace()
. Make sure the changed code is sync'ed to your server.答案 1 :(得分:0)
我终于(最终)使用ssh RemoteForward打开了它,就像这样:
ssh -R 5678:localhost:5678 user@<remotehost>
然后在此ssh会话中启动脚本。 python脚本主机必须连接到localhost:5678,当然您的本地pycharm调试器必须侦听5678 (或您选择的任何端口)