如何在PyCharm中进行远程调试 [英] How to remote debug in PyCharm
问题描述
我现在面临的问题:
- 我通过SSH在远程主机上部署Python代码
- 脚本传递了一些参数,并且必须由特定用户运行
- 我创建的PyCharm运行/调试配置通过另一个用户通过SSH连接(不能与实际运行脚本的用户连接)。
- 我想通过PyCharm远程调试此代码...我设法进行了所有配置,只是得到了权限错误。
- I deploy Python code on a remote host via SSH
- the scripts are passed some arguments and must be ran by a specific user
- the PyCharm run/debug configuration that I create connects through SSH via a different user (can't connect with the user that actually runs the scripts)
- I want to remote debug this code via PyCharm...I managed to do all configuration, I just get permission errors.
有什么方法可以作为特定用户(例如sudo su-user)运行/调试脚本?
Are there any ways on how I can run/debug the scripts as a specific user (like sudo su - user)?
我已经阅读了有关在PyCharm的远程/调试配置中指定一些Python Interpeter选项的信息,但没有找到有效的解决方案。
I've read about specifying some Python Interpeter options in PyCharm's remote/debug configuration, but didn't manage to get a working solution.
推荐答案
如果您想要一种简单且更灵活的方式进入PyCharm调试器,而不必一定要在PyCharm中单击播放按钮,则可以使用调试服务ver 功能。我在运行某些Python代码不像运行 python ...
那样简单的情况下使用过此代码。
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 ...
.
请参阅使用Python Debug Server文档进行远程调试更多详细信息,但这是它的工作原理的粗略总结:
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
- 上传&在服务器上安装远程调试帮助程序鸡蛋(在OSX上,这些文件位于
/Applications/PyCharm.app/Contents/debug-eggs
下) - 设置远程调试服务器的运行配置:单击下拉运行配置菜单,选择
编辑配置...
,按+
按钮,选择Python远程调试
。
- 此处输入的详细信息(有些令人困惑)告诉运行Python脚本的远程服务器如何连接到笔记本电脑的PyCharm实例。
- 设置
本地主机名
到笔记本电脑的IP地址 - 设置
端口
到您可以在笔记本电脑上使用的任何免费端口(例如8888
)
- Upload & install remote debugging helper egg on your server (On OSX, these are found under
/Applications/PyCharm.app/Contents/debug-eggs
) - Setup remote debug server run configuration: click on the drop-down run configuration menu, select
Edit configurations...
, hit the+
button, choosePython remote debug
.- The details entered here (somewhat confusingly) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
- set
Local host name
to your laptop's IP address - set
port
to any free port that you can use on your laptop (e.g.8888
)
这篇关于如何在PyCharm中进行远程调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!