ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_collect_try_except_info'
Following the README, I get this error inside the IPyIDA console when I attempt to launch debug from PyCharm
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
File ~/bin/pycharm-2022.2.2/plugins/python/helpers/pydev/pydevd.py:16
13 if here not in sys.path:
14 sys.path.insert(0, here)
---> 16 from _pydevd_bundle.pydevd_collect_try_except_info import collect_return_info
18 if sys.version_info[:2] < (2, 6):
19 raise RuntimeError('The PyDev.Debugger requires Python 2.6 onwards to be run. If you need to use an older Python version, use an older version of the debugger.')
ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_collect_try_except_info'
Likely a few solutions here, including adding the PyCharm folders to the system interpreter paths (feels messy). Filing this as an issue since it doesn't seem to work out of the box with IDA 8.2 and PyCharm 2022+
That's interesting, because I could swear that debugging was working back when I initially uploaded the code (especially that I remember someone on Twitter explicitly asked me about debugging in relation to this tutorial). I can confirm that this is also happening on my side now.
On the other hand, I had a similar error one day, but it was when I was trying to run the code normally, after doing a debug run. Trying to fix it took me more time than I was able to devote at the time, so I just resorted to restarting IDA after debugging.
Have you found a reliable way of fixing this issue? Does adding the folders fix it or are you just expecting it will fix that but haven't tried that yet? I may expand the readme if the change to make is simple enough
Not yet. I've tried extending sys.path both at the IPython console (prior to launching debug) and inside the pydevd.py script. I even modified the script to include the complete sys.path from the PyCharm project and no dice.
I did play around in the IDA IPython console after seeing this failure and noticed something interesting.
import _pydevd_bundle
print(_pydevd_bundle.__file__)
/home/user/.local/lib/python3.8/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__init__.py
Maybe IPyIDA interprets the import paths differently then PyCharm? It should be able to co-exist with an existing debugpy installation, as long as it prioritizes the imports the same way PyCharm would
As a side-note, code just prior to the import adds the file's directory to the path stating that this is to ensure importing works even in isolated mode, so adding the directory to the path yourself is unlikely to help.
I've also taken a peek and it looks like going to the right directory and then typing:
from _pydevd_bundle.pydevd_collect_try_except_info import collect_return_info
works with a regular python installation, but the same line executed in IPyIDA fails (note that you can do a simple "cd" in IPython to change directories).
Even import _pydevd_bundle.pydevd_collect_try_except_info fails.
~~My guess is that there may be an issue deeper, with modules that are imported by pydevd_collect_try_except_info and that that issue is then shadowed by a blanket except Exception: raise ModuleNotFoundError, figuratively speaking.
Either something is unavailable from IPyIDA or maybe the binary .pyd files fail to import?~~
It may also be worth asking on the IPyIDA issue tracker
Actually I completely missed the second part of your message 🤦
You're completely right: _pydevd_bundle is imported from debugpy and since we're looking for a subpackage and the (wrong) package is already imported, then it tries to do a relative import and fails.
Something is importing _pydevd_bundle even before pydevd.py is executed, because if you print(sys.modules['_pydevd_bundle']) inside pydevd.py, that module is already loaded by the time sys.path is extended.
Ok @agentzappo, I managed to get it to work, but with a really dirty workaround, for now. Replace the last line of the pycharm_wrapper.py with:
if 'helpers/pydev/pydevd.py' in args.path:
import sys
import time
# FIXME: Such an ugly workaround! :[
for name in sys.modules.copy():
if 'pydev' in name:
del sys.modules[name]
manager.client().execute(command, store_history=True, allow_stdin=True, reply=True)
# Sleep here because as soon as this ends, PyCharm debugging stops
while True:
time.sleep(1)
else:
manager.client().execute(command, store_history=True, allow_stdin=True, reply=True)
You also have to stop debugging manually, because the wrapper has currently no way of knowing when the file being executed actually stopped executing, but this will have to do, for now.
Also, I have no idea what will break later, since we just unloaded the pydev library used by IPyIDA itself (or one of its dependencies).
As always, PR-s are welcome :)
EDIT: I might have talked too soon and used code that "works on my machine". You may be forced to delete the modules by inserting the for loop into pydevd.py instead of in the wrapper. Then once you do that, the code above should work.
Hey! I fixed that issue with ModuleNotFoundError in https://github.com/overfl0/IDAPython-pycharm-setup/commit/fcb627c339070101c12eb2eca6bd958c2a047c2f !
If I said I'll fix it, then I'll fix it. No need to remind me every year! ;)