Help me start a debugging session with pudb
#1  paulriddle 09-29-2020, 04:37 AM
This is not a question about pudb specifically, I am more interested in figuring out why Python doesn't see the module I installed.

Hello. My goal is to debug calibre with external debugger

I insert breakpoint here:

Breakpoint looks like this:
import pudb; pu.db
I run calibre as

calibre-debug -- /path/to/
It says

Traceback (most recent call last): File "", line 194, in _run_module_as_main File "", line 87, in _run_code File "", line 48, in <module> File "", line 44, in main File "/home/paulriddle/code/calibre/src/calibre/", line 336, in main run_script(args[1], args[2:]) File "/home/paulriddle/code/calibre/src/calibre/", line 243, in run_script exec_path(ef, g) File "/home/paulriddle/code/calibre/src/polyglot/", line 110, in exec_path exec(code, ctx) File "/home/paulriddle/code/calibre/src/calibre/ebooks/mobi/debug/", line 51, in <module> main() File "/home/paulriddle/code/calibre/src/calibre/ebooks/mobi/debug/", line 46, in main import pudb; pu.db
ModuleNotFoundError: No module named 'pudb'
I try installing pudb using 3 methods:

1. pip install --user pudb
2. pip install pudb
3. pipx install pudb
None of them helped calibre detect the module. I'm really new to Python, so I'm not sure what I am doing wrong. I installed calibre using the binary installer, and *not* my package manager (pacman on ArchLinux). Although I tried installing with my package manager as well, it did not help.

I set
and made sure my shell is reloaded. This way the suggested methods of debugging work, for example I can insert print statement in the checked out source and calibre will execute them. The question is how do I integrate an external debugger like pudb with calibre? Because I'm new to Python I'd like to have the extra interactivity that pudb provides, it will help me understand the code in the beginning.

Python 3.8.5

#2  kovidgoyal 09-29-2020, 07:53 AM
The calibre binaries come with their own private python. If you want to import an external package you have to insert the path to that package into sys.path

#3  paulriddle 09-29-2020, 08:45 AM
Thank you for the reply. I don't know about sys.path editing, but I managed to get it working another way. Instead of installing calibre via binary installer, I used my system package manager, pacman. Then I installed pudb with pip install pudb. For some reason it didn't ask for root permissions, but ok. Then I could insert breakpoints with import pudb; pu.db and it worked.

Anyways, knowing that calibre ships with it's own python gives me a clue of where to look when issues arise.

#4  eschwartz 09-30-2020, 02:05 PM
As Kovid said, if you use the binary installer it's more complicated to add additional modules. But also if you're going to use the [community] package then you might as well also use

Don't ever use pipx. Pipx is intended for creating one virtualenv for each module you install, the virtualenv contains copies of every dependent module and in order to add the library path you need to run the module using pipx.

It's an unwisely created piece of software which is basically "docker for python" and it doesn't interoperate with anything else anywhere ever.

"pip install pudb" would work fine, by default pip does a local user install (as if you specified pip install --user pudb) for precisely the issue of you should not need root for this.

Note that for the distro binaries rather than the official prebuilt binaries, you will want to override the source code using "export CALIBRE_PYTHON_PATH" rather than CALIBRE_DEVELOP_FROM.

#5  The_book 10-01-2020, 09:50 AM
may be helpful to show how to import an external package you have to insert the path to that package into sys.path

Today's Posts | Search this Thread | Login | Register