Hi,
Copying Python's binary files from one version to the other is not recommended.
I have PyMuPdf latest version installed on my Python 3.12.6 environment:
C:\>pip show pymupdf
Name: PyMuPDF
Version: 1.24.11
Summary: A high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
Home-page:
Author: Artifex
Author-email: support@artifex.com
License: GNU AFFERO GPL 3.0
Location: C:\Users\Usuario\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires:
Required-by:
Trying to import it from Fusion (which includes Python 3.12.4) I was able to reproduce your error:
Traceback (most recent call last):
File "C:\fusion/fusion_script/testings\_t24_pymupdf.py", line 7, in <module>
import pymupdf
File "C:\Users/Usuario/AppData/Local/Programs/Python/Python312/Lib/site-packages\pymupdf\__init__.py", line 30, in <module>
from . import extra
File "C:\Users/Usuario/AppData/Local/Programs/Python/Python312/Lib/site-packages\pymupdf\extra.py", line 10, in <module>
from . import _extra
ImportError: DLL load failed while importing _extra: No se puede encontrar el módulo especificado.
Since I found a this report in github's source:
C:\>pip install pymupdf==1.24.9
Collecting pymupdf==1.24.9
Using cached PyMuPDF-1.24.9-cp312-none-win_amd64.whl.metadata (3.4 kB)
Collecting PyMuPDFb==1.24.9 (from pymupdf==1.24.9)
Using cached PyMuPDFb-1.24.9-py3-none-win_amd64.whl.metadata (1.4 kB)
Using cached PyMuPDF-1.24.9-cp312-none-win_amd64.whl (3.2 MB)
Using cached PyMuPDFb-1.24.9-py3-none-win_amd64.whl (13.2 MB)
Installing collected packages: PyMuPDFb, pymupdf
Attempting uninstall: PyMuPDFb
Found existing installation: PyMuPDFb 1.24.10
Uninstalling PyMuPDFb-1.24.10:
Successfully uninstalled PyMuPDFb-1.24.10
Attempting uninstall: pymupdf
Found existing installation: PyMuPDF 1.24.10
Uninstalling PyMuPDF-1.24.10:
Successfully uninstalled PyMuPDF-1.24.10
Successfully installed PyMuPDFb-1.24.9 pymupdf-1.24.9
and it worked.
This is the code snippet I used to test it:
import adsk, adsk.core, adsk.fusion, adsk.cam, traceback
import sys
PYTHON_LIBS_PATH = "C:/Users/Usuario/AppData/Local/Programs/Python/Python312/Lib\site-packages"
if PYTHON_LIBS_PATH not in sys.path:
sys.path.append(PYTHON_LIBS_PATH)
import pymupdf
app = adsk.core.Application.get()
doc = app.activeDocument
des: adsk.fusion.Design = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
# Same error reported before suggest to downgrade to 1.24.9 version:
# https://github.com/pymupdf/PyMuPDF/issues/3598#issuecomment-2351571541
def run(context) -> None:
try:
app.log(f'{pymupdf.version=}')
app.log(f'{pymupdf.__doc__=}')
try:
doc = pymupdf.open("c:/99tmp/sample.pdf")
app.log(f"PDF opened successfully: {doc=} {doc.page_count=}")
app.log(f"{doc.metadata=}")
except Exception as e:
app.log(f"An error occurred: {e}")
except:
app.log('Failed:\n{}'.format(traceback.format_exc()))
adsk.terminate()
And this the result I get:
pymupdf.version=('1.24.9', '1.24.8', '20240724000001')
pymupdf.__doc__='PyMuPDF 1.24.9: Python bindings for the MuPDF 1.24.8 library (rebased implementation).\nPython 3.12 running on win32 (64-bit).\n'
PDF opened successfully: doc=Document('c:/99tmp/sample.pdf') doc.page_count=22
doc.metadata={'format': 'PDF 1.7', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': '', 'producer': 'GPL Ghostscript 9.53.3', 'creationDate': "D:20230703123842Z00'00'", 'modDate': "D:20230703123842Z00'00'", 'trapped': '', 'encryption': None}
I hope this can help.
Regards,
Jorge Jaramillo