Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 09-29-2020, 03:37 AM   #1
paulriddle
Junior Member
paulriddle began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Sep 2020
Device: none
Help me start a debugging session with pudb

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 https://documen.tician.de/pudb/starting.html

I insert breakpoint here:

https://github.com/kovidgoyal/calibr...ug/main.py#L45

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

Code:
calibre-debug main.py -- /path/to/ebook.mobi
It says

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

Code:
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
Code:
CALIBRE_DEVELOP_FROM=/home/paulriddle/code/calibre/src
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
paulriddle is offline   Reply With Quote
Old 09-29-2020, 06:53 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
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
kovidgoyal is offline   Reply With Quote
Old 09-29-2020, 07:45 AM   #3
paulriddle
Junior Member
paulriddle began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Sep 2020
Device: none
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.
paulriddle is offline   Reply With Quote
Old 09-30-2020, 01:05 PM   #4
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
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 https://www.archlinux.org/packages/c...y/python-pudb/

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.
eschwartz is offline   Reply With Quote
Old 10-01-2020, 08:50 AM   #5
The_book
Zealot
The_book began at the beginning.
 
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
https://www.mobileread.com/forums/sh...d.php?t=228173
may be helpful to show how to import an external package you have to insert the path to that package into sys.path
The_book is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Timeout Pizza_Cant_Read Feedback 4 11-24-2017 07:07 PM
V3 does not run in remote session loviedovie Calibre 1 06-28-2017 11:26 PM
Automatically restore last session? Roboticist Library Management 3 07-31-2015 12:01 PM
Update metadata once per session possible? Ripplinger Calibre 0 11-24-2012 09:10 PM
minutes each session? IxiaAurea Kobo Reader 11 09-10-2011 10:31 PM


All times are GMT -4. The time now is 04:18 PM.


MobileRead.com is a privately owned, operated and funded community.