Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 01-15-2019, 09:15 AM   #1
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Error on using numpy package into plugin

Hi,

I am writing a plugin which use numpy python package.
But everytime I got this error:

Quote:
Error:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray'
I have googled but did not find a suitable solution.

Has anyone an idea or help me please?

Thank you
nirosan is offline   Reply With Quote
Old 01-15-2019, 11:45 AM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 19,613
Karma: 100000000
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Numpy is not part of Sigil's bundled python environment. So any plugin wanting to use it would need to include it with the plugin (no idea how one might pull that off), or use an external python environment for Sigil plugins that already had numpy properly installed. Properly installing numpy in an external python environment would likely be a numpy question rather than a Sigil one.

The real question is: what do you need to do to an epub that could possibly require a scientific computing module like NumPy?

Last edited by DiapDealer; 01-15-2019 at 11:51 AM.
DiapDealer is offline   Reply With Quote
Old 01-16-2019, 06:19 AM   #3
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Thank you.
I had include numpy package and other required packages into my plugin package but got the same error. If I use local python interpreter then its works. But the packages whick I inlcuded are from the same python directory. The user of the plugin should be able to use it with the sigil bundled python and included packages. Therefore I need a solution.

The plugin which I write is to render Latex math formulas notation into mathml. To display the rendered formulas with symbols I need matplotlib package and matplotlib need numpy.
nirosan is offline   Reply With Quote
Old 01-16-2019, 07:38 AM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 19,613
Karma: 100000000
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I'm assuming you're creating an input plugin then? Otherwise, a sigil plugin won't help you render/display anything.

As to how to package numpy/matplotlib to work in Sigil's bundled python environment, I'm afraid I can't help. I suspect that would be relatively complicated (not to mention large) to accomplish. Pure Python modules are fairly easy to relocate/include. Binary packages can be quite involved and include hardcoded paths or environment variables necessary to function properly.

Also note that it's not likely your plugin would work on all Sigil platforms (Windows, OSX, Linux). If installed via pip or your package manager (or other binary media), your compiled modules are going to be platform specific. The binary wheels are also usually specific to a particular Python version. So even if you manage to get something working with Sigil's bundled Python, it's likely to break when we upgrade the version of python that we bundle.

For binary dependencies, it's simply going to be best to use an external, python interpreter to run the plugin. That way, you can have your users install the binary dependencies.

Last edited by DiapDealer; 01-16-2019 at 07:47 AM.
DiapDealer is offline   Reply With Quote
Old 01-16-2019, 08:23 AM   #5
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Thank you for your quick reply.

Yes is it an input plugin. I am trying some solutions but not works. Another way is to display on QWebEngineView. Is QtWebEngineWidgets part of sigil bundled python environment? May be not I got this error:

Quote:
from PyQt5.QtWebEngineWidgets import QWebEngineView
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
Error: No module named 'PyQt5.QtWebEngineWidgets'
How can I include QWebEngineWidgets in my plugin?

Thank you
nirosan is offline   Reply With Quote
Old 01-16-2019, 09:39 AM   #6
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 19,613
Karma: 100000000
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by nirosan View Post
Thank you for your quick reply.

Yes is it an input plugin. I am trying some solutions but not works. Another way is to display on QWebEngineView. Is QtWebEngineWidgets part of sigil bundled python environment?
No, it is not part of the PyQt5 module we include with our bundled Python. Worse than that, Sigil doesn't include QWebEngine(View) with its Qt5. Sigil only utilizes QtWebKit (and no, we don't include the PyQt5 interface module to QtWebKit either).

Sigil's plugin framework was never intended to be able to do a lot of high-level rendering. We've only included enough modules for people to do some basic Widgets (PyQt and Tkinter) to utilize in gui interfaces intended to get user input for their plugins' parameters.

Quote:
Originally Posted by nirosan View Post
How can I include QWebEngineWidgets in my plugin?
To put it quite bluntly: you can't. Sorry. Sigil plugins were not intended to be used to display content. They're intended to import/edit/validate/export content.

Last edited by DiapDealer; 01-16-2019 at 09:42 AM.
DiapDealer is offline   Reply With Quote
Old 01-16-2019, 10:49 AM   #7
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,417
Karma: 14368669
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by nirosan View Post
To display the rendered formulas with symbols I need matplotlib package and matplotlib need numpy.
BTW, Sigil (and some epub3 apps) display MathML formulas in epub3 books without conversion. I.e., you won't have to convert MathML formulas, unless you limit yourself to epub2 books. (For MathML examples, see EPUBTEST 0100 - Reflowable Content Tests.)

IIRC, there are also some Python packages and standalone PostScript/LaTex/MathML to SVG converters that you could use, if you don't want to support epub3 books. (Many epub2 apps support SVG images.)
Doitsu is offline   Reply With Quote
Old 01-19-2019, 04:31 AM   #8
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Thank you

Yes It is better to transfer mathml into svg and display. Now I am searching for a python module for that.
Thank you for your quick replies.
nirosan is offline   Reply With Quote
Old 01-19-2019, 12:44 PM   #9
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 1,146
Karma: 6100569
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by nirosan View Post
The plugin which I write is to render Latex math formulas notation into mathml. [...] Now I am searching for a python module for that.
plastex could potentially be a solution. It's written in Python, and does TeX -> HTML.

There's also these two answers on the LaTeX Stack Exchange that cover some other tools:

https://tex.stackexchange.com/questi...mathml-and-tex
https://tex.stackexchange.com/questi...and-approaches

(tex4ht converts LaTeX -> HTML, and very customizable.)

Quote:
Originally Posted by nirosan View Post
Yes It is better to transfer mathml into svg and display.
You could use some of the above tools to LaTeX -> MathML, and then go MathML -> SVG+PNG.

Or I personally go LaTeX -> PDF -> SVG+PNG.

I wrote about that most recently in this topic. (Also, if you check out the ebookcraft 2018 "Equations in Ebooks" slides, you may get some more methods/ideas too.)

If you're putting this book up for sale on the major retailers, you have to keep in mind the millions of older devices out there that can't read/render MathML, so you must design these image fallbacks anyway. Can't rely on purely MathML, which is a shame.

Last edited by Tex2002ans; 01-19-2019 at 12:48 PM.
Tex2002ans is offline   Reply With Quote
Old 01-22-2019, 09:25 AM   #10
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Thank you.

I already use some python modules to convert latex and asciimath into mathml and it works fine. (Modules: latex2mathml and asciitomathml).

What I need is a python module to convert the mathml into svg or any images to display the rendered mathml. The user should be able to see the rendered formula before she/he can add it into the book.

What I had used is with matplotlib module:

Quote:
dpi = 300
fig = plt.figure(figsize=(0.01, 0.01))
fig.text(0, 0, r'${}$'.format(self.formulas_input.text()), fontsize=fontsize)

output = BytesIO()
fig.savefig(output, dpi=dpi, transparent=True, format='svg',
bbox_inches='tight', pad_inches=0.0, frameon=False)
plt.close(fig)

output.seek(0)
svg_output = output.read()
self.render_svg.load(svg_output)
The problem was matplotlib use numpy.

I did not find a suitable python module to write mathml into svg which can I load into QSvg to display it.
nirosan is offline   Reply With Quote
Old 01-29-2019, 06:25 AM   #11
nirosan
Member
nirosan began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2017
Device: epub
Thank you

I found a workaround:

- transform latex formulas into png

Quote:
...
requests.get('http://latex.codecogs.com/png.latex?\dpi{{300}} {formula}'.format(formula=formula))
...
- load png into QPixmap to display it on the editor
nirosan is offline   Reply With Quote
Reply

Tags
mathml, multiarray, numpy, plugin

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using wordpress_xmlrpc package in my plugin wrench100 Development 4 08-17-2018 08:17 PM
iTunes Producer "package.opf" error MatMu ePub 3 11-19-2017 08:05 PM
Multi-plugin package jgoguen Development 5 05-25-2015 05:21 PM
Calibre plugIn Kindle Collections Error message "Value Error:month..." readee Plugins 4 10-10-2011 12:21 PM
PRS-505 Error: package.opf is over 300KB papilonv Sony Reader 1 09-17-2010 08:18 AM


All times are GMT -4. The time now is 07:27 PM.


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