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 01-06-2018, 03:56 PM   #1
einnordlicht
Junior Member
einnordlicht began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jan 2018
Device: none
Problems using Calibre 3.15.0 Database API

Hi,
sorry for the rookie question but I have trouble to get the Calibre database running. I'm trying my first steps to write an external (standalone) python program to extend the Calibre metadata of my Calibre library with some thousands of Amazon books.
The environment is KUbuntu 16.04.3, Calibre 3.15.0. I followed the installation instructions from https://manual.calibre-ebook.com/develop.html and installed a binary Calibre 3.15.0 and the source code from git. Python is 2.7.12.

I try to create a very simple program in the src folder ($CALIBRE_DEVELOP_FROM) and point it to my Calibre test library
Code:
from calibre.library import db
db = db('/home/myuserid/Calibre Library').new_api
but all I get is
Code:
python calibreDbTest.py
Hello, world!
Traceback (most recent call last):
  File "calibreDbTest.py", line 1, in <module>
    from calibre.library import db
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/__init__.py", line 23, in <module>
    from calibre.startup import winutil, winutilerror
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/startup.py", line 85, in <module>
    import calibre.utils.resources as resources
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/utils/resources.py", line 67, in <module>
    _resolver = PathResolver()
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/utils/resources.py", line 18, in __init__
    self.locations = [sys.resources_location]
AttributeError: 'module' object has no attribute 'resources_location'
/home/myuserid/Nextcloud/work/calibre/src/calibre/ptempfile.py:29: RuntimeWarning: Parent module 'calibre' not found while handling absolute import
  import shutil
Do I miss anything essential here?
Thanks for hints and help
Regards
einnordlicht
einnordlicht is offline   Reply With Quote
Old 01-06-2018, 05:45 PM   #2
sjfan
Addict
sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.
 
Posts: 281
Karma: 7724454
Join Date: Sep 2017
Location: Bethesda, MD, USA
Device: Kobo Aura H20, Kobo Clara HD
Quote:
Originally Posted by einnordlicht View Post
Hi,
sorry for the rookie question but I have trouble to get the Calibre database running. I'm trying my first steps to write an external (standalone) python program to extend the Calibre metadata of my Calibre library with some thousands of Amazon books.
The environment is KUbuntu 16.04.3, Calibre 3.15.0. I followed the installation instructions from https://manual.calibre-ebook.com/develop.html and installed a binary Calibre 3.15.0 and the source code from git. Python is 2.7.12.

I try to create a very simple program in the src folder ($CALIBRE_DEVELOP_FROM) and point it to my Calibre test library
Code:
from calibre.library import db
db = db('/home/myuserid/Calibre Library').new_api
but all I get is
Code:
python calibreDbTest.py
Hello, world!
Traceback (most recent call last):
  File "calibreDbTest.py", line 1, in <module>
    from calibre.library import db
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/__init__.py", line 23, in <module>
    from calibre.startup import winutil, winutilerror
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/startup.py", line 85, in <module>
    import calibre.utils.resources as resources
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/utils/resources.py", line 67, in <module>
    _resolver = PathResolver()
  File "/home/myuserid/Nextcloud/work/calibre/src/calibre/utils/resources.py", line 18, in __init__
    self.locations = [sys.resources_location]
AttributeError: 'module' object has no attribute 'resources_location'
/home/myuserid/Nextcloud/work/calibre/src/calibre/ptempfile.py:29: RuntimeWarning: Parent module 'calibre' not found while handling absolute import
  import shutil
Do I miss anything essential here?
Thanks for hints and help
Regards
einnordlicht
Take a look at /usr/bin/calibre or /usr/bin/calibredb or similar, you'll see that it sets up a bunch of variables on sys before running things:
Code:
path = os.environ.get('CALIBRE_PYTHON_PATH', '/usr/lib/calibre')
if path not in sys.path:
    sys.path.insert(0, path)

sys.resources_location = os.environ.get('CALIBRE_RESOURCES_PATH', '/usr/share/calibre')
sys.extensions_location = os.environ.get('CALIBRE_EXTENSIONS_PATH', '/usr/lib/calibre/calibre/plugins')
sys.executables_location = os.environ.get('CALIBRE_EXECUTABLES_PATH', '/usr/bin')
There's code in setup/install.py to add this header to all calibre executables, and if you're running things out of the source directory setup/__init__.py should set them relative to the src tree.
sjfan is offline   Reply With Quote
Advert
Old 01-06-2018, 09:28 PM   #3
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,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You run your python script with calibre-debug not with python.

https://manual.calibre-ebook.com/dev...on-environment
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aura H2O Database problems (recurring) Oolong Kobo Reader 3 07-06-2017 04:15 PM
Database problems tdp1947 Calibre 15 06-19-2015 03:51 PM
Calibre update breaks Calibre API TechnoCat Recipes 5 01-28-2013 11:25 PM
problems with calibre database killa Calibre 1 06-09-2012 11:40 PM
calibre's new plugin API kovidgoyal Plugins 26 05-07-2011 02:43 PM


All times are GMT -4. The time now is 11:54 PM.


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