Quote:
Originally Posted by einnordlicht
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.