![]() |
#1 |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Plugins and optional Python modules
Calibre plugins seem to run with Calibre's python installation. How can I access an optional module that isn't installed in Calibre's python setup? E.g. PyCrypto?
|
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,686
Karma: 874275
Join Date: Nov 2008
Location: Virginia Beach, VA
Device: Kindle DX
|
PyCrypto is a separate install and the following link may be of use:
http://dearauthor.com/wordpress/2010...-and-pycrypto/ |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
|
|
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,686
Karma: 874275
Join Date: Nov 2008
Location: Virginia Beach, VA
Device: Kindle DX
|
not at all...
|
![]() |
![]() |
![]() |
#5 |
Gadget Freak
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,169
Karma: 1043832
Join Date: Nov 2007
Location: US
Device: EE, Note 8
|
I have installed the 'complete' Windows Python environment - No issues with Calibre.
* For reference, Calibre was installed first, only because I was using it prior to the 'need' for the Python environment. * Running Windows Vista Home Premium 32 bit. Gunner... |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,263
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Stick it in the the plugin zip file. If your extra modules don't contain any compiled code (files ending with .so) that is all you need to do. If they do, the you have to unzip the zip file into a temporary directory and add that to sys.path in your plugin code.
|
![]() |
![]() |
![]() |
#7 | |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
|
|
![]() |
![]() |
![]() |
#8 | |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
ERROR: ERROR: Unhandled exception: <b>ImportError</b>:No module named Crypto.Cipher Traceback (most recent call last): File "site-packages/calibre/gui2/dialogs/config/__init__.py", line 531, in add_plugin File "site-packages/calibre/customize/ui.py", line 271, in add_plugin File "site-packages/calibre/customize/ui.py", line 67, in load_plugin File "<string>", line 34, in <module> ImportError: No module named Crypto.Cipher Looking at ui.py, line 67, it seems to me that at this point it has only decompressed the _plugin file, and not the module that's also included in the zip file. If it does a similar ting later when trying to execute, that would explain why things are not working. Perhaps I'll need to do what you suggested later, and include the module as a zipped file, and explicitly unzip to a temporary folder and add to sys.path? Or should it be working, and I've just done something wrong in adding in the module to the zip file? Thanks. |
|
![]() |
![]() |
![]() |
#9 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,263
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
What happens is the following
Before the plugin is run by ui.py the path to the plugins zip file is added to sys.path python can directly import python modules from zip files, but only python modules Not compiled modules like *.so or *.pyd files. ANother thing to be aware of is that this happens only if you use the run_plugins_on_import function in ui.py |
![]() |
![]() |
![]() |
#10 | |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
My zip file has this structure (folders in italic): myplugin_plugin_zip ....myplugin_plugin.py ....Module ........__init__.py ........Submodule1 ............__init__.py ............variousscripts.py ...........OtherFolders ...............__init__.py ........Submodule2 etc. My plugin sets these up: name = 'myplugin' description = 'myplugin description' supported_platforms = ['linux', 'osx', 'windows'] author = 'me' version = (5, 0, 0) file_types = set(['epub']) on_import = True What do I need to do to get the run_plugins_on_import function to run? Hmm... Better still, I have trimmed everything from the plug-in, except an import of a function from a module. I hope I've got it all right, but there's very little code there, so hopefully I have. I attach the plugin. What's wrong with this plug-in? When trying to add it, I get the error message "No module named TestModule" I'm sorry if I'm missing something basic here. |
|
![]() |
![]() |
![]() |
#11 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,263
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Stick the
from TestModule import TestFunction into the run method (the module will be in sys.path only during invocation of run, not during adding the plugin, etc.) and dont worry about run_plugins_on_import, in this case it is used automatically. Also just so you know, the next release of calibre will automatically handle the case of plugins with compiled code as well as plugins with only python code. |
![]() |
![]() |
![]() |
#12 |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
|
![]() |
![]() |
![]() |
#13 | |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
I suppose it would be possible to produce different versions, or perhaps instructions on how to add a module that's been compiled up separately by the user. Hmm... that's not a bad idea. I'll give it a go. |
|
![]() |
![]() |
![]() |
#14 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,263
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It's possible to make a plugin that is cross platform in this case as well.
What you do is the following (this will only work in the next release of calibre) Put all three versions of the dependency in the plugin zip file, alongwith any needed dlls. Put them in subdirectories called windows, osx, linux Then in the run method of your plugin do this: Code:
from calibre.constants import iswindows, isosx pdir = 'windows' if iswindows else 'osx' if isosx else 'linux' ppath = os.path.join(self.sys_insertion_path, pdir) sys.insert(0, ppath) try: import your_dependency plugin code finally: sys.path.remove(ppath) |
![]() |
![]() |
![]() |
#15 |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72,054
Karma: 307935764
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Optional characters in Save Template for Adding Books | Starson17 | Calibre | 1 | 02-28-2010 12:52 PM |
Process Modules | LarryLaser | Calibre | 3 | 02-10-2010 12:32 PM |
question/suggestion: convert directly and make importing of sourcefile optional | dura | Calibre | 0 | 09-09-2009 06:05 AM |
iLiad USB serial modules | drazvan | iRex Developer's Corner | 8 | 07-30-2007 05:43 PM |
need a reader,bells and whistles optional | Sandra | Which one should I buy? | 14 | 11-17-2005 02:49 AM |