No module named pydevd from QGIS 3

I am trying to set up PyCharm to debug a QGIS 3.6 plugin.  In PyCharm, the line 

    import pydevd

raises no error (no red curly line) and a Ctrl-Click on pydevd brings up the module, so I am certain the installation is good and the paths are correct.  Attempting to load the plugin from QGIS, however, raises the error "ModuleNotFoundError: No module named pydev". The full (redacted) Traceback is as follows:

Traceback (most recent call last):
  File "C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python\qgis\utils.py", line xxx, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "C:/Users/[app data folder]/Roaming/QGIS/QGIS3\profiles\default/python/plugins\[plugin name]\__init__.py", line xx, in classFactory
    from .[program] import [Class]
  File "C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python\qgis\utils.py", line xx, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/Users/[app data folder]/Roaming/QGIS/QGIS3\profiles\default/python/plugins\[plugin name]\[program].py", line xx, in
    import pydevd
  File "C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python\qgis\utils.py", line xx, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'pydevd'

What am I missing?  

Additional info:

PYTHONPATH = C:\Program Files\JetBrains\PyCharm 2018.2.2\debug-eggs\pycharm-debug.egg

PYCHARM_DEBUG = True

4 comments

Please try to run the same code from your system terminal, using the same interpreter and environment. 

If the issue is reproduced only in IDE, please provide screenshots of your project interpreter settings, your run/debug configuration, and logs (https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files).

If you're using Anaconda, please try to delete and recreate the interpreter.

0

Since the code is a QGIS plugin, there is no way to run it from outside of QGIS. I am upgrading a QGIS 2 plugin written in Python 2.7 to a QGIS 3 plugin for Python 3, so there are some challenges in getting the plugin to work at all.  I am attempting to debug the plugin using PyCharm. 

I updated to a new version of PyCharm (2019.1.1) and adjusted the path and python_path variables.   

When I start QGIS Debug, pydevd_pycharm loads and PyCharm waits patiently for a connection:

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

However, when I attempt to load the plugin, I still get the error:

    ModuleNotFoundError: No module named 'pydevd_pycharm'

 

0

>Since the code is a QGIS plugin, there is no way to run it from outside of QGIS

There's no need to run it outside of QGIS. What I'm asking is to check if the issue is reproduced without using IDE. QGIS is not attached to PyCharm in any way.

ModuleNotFound errors are often not related to IDE, but rather to interpreter, environment.

0

Apologies for the delayed response.  I have been tasked with other projects.

After much head scratching and maneuvering in the command prompt and pip install and pip show, etc. I finally got pydevd installed in the correct interpreter.  For the sake of testing outside of QGIS, I created a .py file with nothing in it but import pydevd.  When that worked, I was good to go.

For the benefit of others who may experience similar issues, I have installations of both Python 2 and Python 3, plus additional installations of QGIS 2 and QGIS 3 which each have their own interpreters for Python.  The trick was to make sure that the version of pip I was running was associated with the specific installation of python that I wanted pip to install to.  I navigated to the precise folder where the python.exe file associated with the interpreter was found that I wanted to use, and THEN ran python -m pip install [module] and that got pydevd installed where it belonged.

0

Please sign in to leave a comment.