![]() |
#1 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 33
Karma: 48958
Join Date: May 2017
Device: iPad Pro 9.7"
|
Import module for use in regex function?
I have a (pip installable) python module I want to use in a Calibre regex function that does not exist in calibre's python environment. I therefore get an error when trying to save the function.
Is it possible to add external modules to calibre's python environment, not for development, but just for use in a custom regex function? IOW, I don't want to run calibre in development mode, I just want to be able to use a module that calibre doesn't have installed. I've looked through the regex function portion of the manual, and done a bit of searching here, and have not found anything. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,355
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It's python if you want to import something from somewhere add it to sys.path before doing the import. Assuming your external module is compatible with the version of python it will work fine.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 33
Karma: 48958
Join Date: May 2017
Device: iPad Pro 9.7"
|
Quote:
Do you mean my regular python's sys.path, or calibre's sys.path? The module is in the former; if I run python3 at the command line and import the module, it works fine. But doing the same import in a calibre regex function returns the error. Nor do I know what calibre's sys.path is; my local version has all version-dependent directories, so I assume calibre's does as well. |
|
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,355
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
In the calibre function do
sys.path.append('whatever') import your_module do whatever you want with it sys.path.remove('whatever') |
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 33
Karma: 48958
Join Date: May 2017
Device: iPad Pro 9.7"
|
Ahh, so add the directory where I have the module to the system path temporarily. Excellent, thanks very much; still so much in python I've never had to do.
|
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with S&R RegEx Function | MerlinMama | Editor | 5 | 05-29-2022 02:23 AM |
Predefined regex for Regex-function | sherman | Editor | 3 | 01-19-2020 05:32 AM |
Regex Function about «» and “” | senhal | Editor | 8 | 04-06-2016 02:12 AM |
Import module not in bundled Python | Toxaris | Plugins | 11 | 02-01-2016 01:55 AM |
No Module name Tkinter on plugin import | foghat | Plugins | 1 | 11-11-2010 07:11 PM |