如何在Ubuntu OS中将Qgis与pycharm连接


10

我刚刚开始将pycharm与qgis结合使用,但无法同时连接它们两者。Pycharm始终处于“等待连接”状态。大多数可用的教程都指向Windows,但是我使用的是ubuntu,所以找不到在pycharm上调试qgis代码的方法。这是我的pycharm代码:

from shapely.geometry import *
from shapely.wkt import loads

import sys

import pydevd

pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)

class Loader:

    def __init__(self, iface):

        """Initialize using the qgis.utils.iface
        object passed from the console.

        """
        self.iface = iface

我在pycharm中启用了断点,并在pythonpath中添加了pycharm-debug.egg,有人从ubuntu上的qgis如何配置它吗?

pycharm始终位于:

Starting debug server at port 53100
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)
Waiting for process connection...

当我从qgis在顶部运行此脚本时,没有任何反应,不会调用断点。


您是否希望Pycharm识别QGIS类?
wondim

Answers:


1

在Arch Linux(但它也应该在Ubuntu上也可以)上,我使用此python脚本,该脚本在QGIS加载时检查是否有人在侦听端口53100。远程调试器。

import psutil


def is_listening_local(port=53100):
    """Return True if someone is listening on the port"""

    els = psutil.net_connections()
    for el in els:
        if el.laddr.port == port:
            return True
    else:
        return False


if is_listening_local():
    try:
        import sys
        # Add the pydevd directory to PYTHONPATH
        sys.path.append('/opt/pycharm-professional/helpers/pydev/')

        import pydevd
        # Connect to the remote debugger
        pydevd.settrace(
            'localhost', port=53100, stdoutToServer=True, stderrToServer=True,
            suspend=False
        )
    except Exception:
        pass

我的完整配置在这里

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.