python3.dll not found

sellis
Advocate

python3.dll not found

sellis
Advocate
Advocate

Last Fusion update broke one of my addins that uses PyMyPDF. Error loading _extra.pyd. After some diagnostics I found it was not loading one of it's dependencies, python3.dll

 

I installed python 3.12.4 and copied python3.dll to C:\Users\*\AppData\Local\Autodesk\webdeploy\production\*\Python. This worked when running from VScode but not while debugging. Tried copying to python3.dll location of _extra.pyd with no success.

 

This seems to be something with Fusion. Any ideas?

0 Likes
Reply
Accepted solutions (2)
394 Views
5 Replies
Replies (5)

Jorge_Jaramillo
Collaborator
Collaborator
Hi,
Is it PyMuPdf instead?
If so, which version did you installed? I can see its latest version is 1.24.11
0 Likes

sellis
Advocate
Advocate

I am using PyMuPDF 1.24.11

 

This was working before last Fusion update. PyMuPDF was finding python3.dll. Python3.dll is included in a standard Python install but does not seem to be included in AppData\Local\Autodesk\webdeploy\production\*\Python. I had an old python install so possible it was being found there.

 

I copied python3.dll to webdeploy\production\*\Python and my scrip works from VScode but not in fusion or while debugging. 

 

I am a hack at python so could very easily be missing something obvious.   

0 Likes

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

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: 

https://github.com/pymupdf/PyMuPDF/issues/3598#issuecomment-2351571541 I decided to downgraded PyMuPdf to version 1.24.9:

 

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

 

1 Like

sellis
Advocate
Advocate
Accepted solution

Thank you!

 

That still didn't work but led me to discover 3 webdeploy\production folders. Each had PyMuPDF installed. After removing PyMuPDF from each it worked with 1.24.9. Looking at the file dates I believe Fusion created a new production folder on last upgrade. Somehow it was trying to load PyMuPDF from an older production folder. I likely caused a bunch of issues trying to fix it by adding paths and such.

 

I did uninstall phython and install to program files but that did not help until I removed the extra PyMuPDF installs. Oddly I had the same error on my home computer so was not a isolated occurrence.   

 

Anyway it works great. Thanks

0 Likes

Jorge_Jaramillo
Collaborator
Collaborator
Hi,
You can always look into sys.path (you might need to import sys before) where the modules are being loaded from.
I more thing I forgot to comment: as you can see in the code I posted before, the module was installed in regular Python version instead of the internal Python that Fusion provides; this way you can keep Fusion clean of any not-standard module, and your deployment can be kept between Fusion upgrades (every upgrade adds a new directory under webdeploy/production folder), at least under the same mayor Python version.
Also you can control from the sys.path list where it needs to look for the module you want.
0 Likes