02-20-2021, 08:50 PM | #1 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
How to import numpy?
I'd like to use numpy for my plugin(for nltk to find named entity) by append 'site-packages' folder to sys.path but I get this error:
Code:
Traceback (most recent call last): File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module> from . import multiarray File "zipimport.py", line 259, in load_module File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module> from . import overrides File "zipimport.py", line 259, in load_module File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "calibre/gui2/threaded_jobs.py", line 83, in start_work File "calibre_plugins.worddumb.parse_job", line 42, in do_job for node in ne_chunk(pos_tag(word_tokenize(text.decode('utf-8')))): File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/nltk/chunk/__init__.py", line 185, in ne_chunk chunker = load(chunker_pickle) File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/nltk/data.py", line 757, in load resource_val = pickle.load(opened_resource) File "zipimport.py", line 259, in load_module File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/numpy/__init__.py", line 145, in <module> from . import core File "zipimport.py", line 259, in load_module File "/Users/x/Library/Preferences/calibre/plugins/WordDumb.zip/.venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.8 from "/Applications/calibre.app/Contents/MacOS/calibre-debug" * The NumPy version is: "1.20.1" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No module named 'numpy.core._multiarray_umath' Last edited by xxyzz; 02-20-2021 at 10:04 PM. |
02-20-2021, 09:42 PM | #2 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
02-20-2021, 10:34 PM | #3 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
I unzipped the site-packages folder but still get the same error:
Code:
Traceback (most recent call last): File "/Users/x/Library/Preferences/calibre/plugins/worddumb-libs1.1/.venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module> from . import multiarray File "/Users/x/Library/Preferences/calibre/plugins/worddumb-libs1.1/.venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module> from . import overrides File "/Users/x/Library/Preferences/calibre/plugins/worddumb-libs1.1/.venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' Last edited by xxyzz; 02-20-2021 at 10:37 PM. |
02-20-2021, 10:53 PM | #4 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You need to include the .so file, and that means a .so file built for the version of python calibre ships with or otherwise one that does not contain version tags like cpython-39-darwin in its file name (which is dangerous since in theory python can break its ABI between versions).
|
02-20-2021, 11:16 PM | #5 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
Oh... I have to match the Python version that calibre uses(3.8) and the platform. Thanks!
|
02-21-2021, 10:15 AM | #6 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
I download the whl file via pip, unzip it then add the folder to sys.path but get this code sign error on mac 11.2.1:
Code:
Traceback (most recent call last): File "/Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/__init__.py", line 22, in <module> from . import multiarray File "/Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/multiarray.py", line 12, in <module> from . import overrides File "/Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/overrides.py", line 7, in <module> from numpy.core._multiarray_umath import ( ImportError: dlopen(/Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so, 2): no suitable image found. Did find: /Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so: code signature in (/Users/x/Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed. |
02-21-2021, 10:27 AM | #7 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yeah apple doesnt like you loading .so files from just anywhere, I doubt there is a way to get this to work on macOS
|
02-21-2021, 07:23 PM | #8 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
I tried to sign all the .so files with my signing identity but get another import error(ad-hoc signing doesn't work):
Code:
ImportError: dlopen(Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so, 2): no suitable image found. Did find: Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so: code signature in (Library/Preferences/calibre/plugins/worddumb-numpy1.20.1/numpy/core/_multiarray_umath.cpython-38-darwin.so) not valid for use in process using Library Validation: mapping process and mapped file (non-platform) have different Team IDs |
02-21-2021, 10:16 PM | #9 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yes, once can disable library validation at build time, but this is not suitable for general calibre builds. You could possibly workaround it by either:
a) disabling gatekeeper on your mac b) building calibre from source yourself c) re-doing the code-signing of the entire calibre bundle using an adhoc signing key and removing the library validation restriction when doing so And yeah, this whole thing is utterly ridiculous on Apple's part. It's so, umm moronic, that they allow processes to load code in the form of text files, but not pre-compiled code, as if one is more or less capable than the other of doing harm. |
02-23-2021, 12:38 AM | #10 |
Evangelist
Posts: 413
Karma: 2666666
Join Date: Nov 2020
Device: none
|
I will skip mac for now, all three methods are very cumbersome just for a plugin to work. I totally agree with you, apple has lots of restrictions in the name of security but not all of them are necessary.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Import Author And Title From Filename & Import Other Tags And Cover From File | DazJWood | Library Management | 25 | 10-06-2021 10:18 AM |
Error on using numpy package into plugin | nirosan | Plugins | 10 | 01-29-2019 05:25 AM |
Export/Import all Calibre data - import error | IanKBrown | Calibre | 5 | 02-15-2017 08:32 PM |
Import on Filename changes mid import due to book error | Vortex | Calibre | 3 | 12-05-2014 11:49 AM |
Import failed Error:404 when attempting to import from Calibre to Stanza | dvond | Apple Devices | 0 | 05-13-2011 03:00 PM |