pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.2k stars 498 forks source link

Windows 10 ImportError: DLL load failed while importing _fitz: 找不到指定的模块。 #2678

Closed yuchangfu closed 1 year ago

yuchangfu commented 1 year ago

system:Windows 10 64 python:Python 3.10.11 amd64 pypdf:1.23.3

after use pip install PyMuPdf,get error

Type "help", "copyright", "credits" or "license" for more information.

import fitz Traceback (most recent call last): File "", line 1, in File "C:\Users\yuc\AppData\Local\Programs\Python\Python310\lib\site-packages\fitz__init__.py", line 22, in from fitz.fitz import * File "C:\Users\yuc\AppData\Local\Programs\Python\Python310\lib\site-packages\fitz\fitz.py", line 14, in from . import _fitz ImportError: DLL load failed while importing _fitz: 找不到指定的模块。

julian-smith-artifex-com commented 1 year ago

Thanks for reporting this.

[According to Google, 找不到指定的模块。 translates to Can't find the specified module.]

I've just checked and things work fine for me on Windows, so i'm not sure what's going wrong for you here.

  1. Are you in a Python venv when installing/using fitz?
  2. Could you post the exact command you used to install PyMuPDF? It would also be useful if you posted the complete output from this command when installing into a new venv.
  3. Please post the output of: pip show pymupdf.
  4. Please post the output of: pip show pymupdfb.
yuchangfu commented 1 year ago

I changed Python version to 3.10.7 ,this version work fine on my other computer,but on this computer the error are same.

  1. I am not't use venv
  2. use command 'pip install pymupdf --no-cache-dir',and install success. C:\Users\yuc>pip install pymupdf --no-cache-dir Defaulting to user installation because normal site-packages is not writeable Collecting pymupdf Obtaining dependency information for pymupdf from https://files.pythonhosted.org/packages/de/ff/0c16387c329023ab76d860329202a6c1b9c59291adfa4869f0fe16659646/PyMuPDF-1.23.3-cp310-none-win_amd64.whl.metadata Downloading PyMuPDF-1.23.3-cp310-none-win_amd64.whl.metadata (3.4 kB) Requirement already satisfied: PyMuPDFb==1.23.3 in c:\users\yuc\appdata\roaming\python\python310\site-packages (from pymupdf) (1.23.3) Downloading PyMuPDF-1.23.3-cp310-none-win_amd64.whl (3.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 23.4 kB/s eta 0:00:00 Installing collected packages: pymupdf Successfully installed pymupdf-1.23.3 After install I test it,get this ` C:\Users\yuc>python Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

    import fitz Traceback (most recent call last): File "", line 1, in File "C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz__init__.py", line 22, in from fitz.fitz import * File "C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz\fitz.py", line 14, in from . import _fitz ImportError: DLL load failed while importing _fitz: 找不到指定的模块。

    `

3.pip show pymupdf ` C:\Users\yuc>pip show pymupdf Name: PyMuPDF Version: 1.23.3 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\yuc\appdata\roaming\python\python310\site-packages Requires: PyMuPDFb Required-by:

4.pip show pymupdfb C:\Users\yuc>pip show pymupdfb Name: PyMuPDFb Version: 1.23.3 Summary: MuPDF shared libraries for PyMuPDF. Home-page: Author: Artifex Author-email: support@artifex.com License: GNU AFFERO GPL 3.0 Location: c:\users\yuc\appdata\roaming\python\python310\site-packages Requires: Required-by: PyMuPDF `

Thank you

julian-smith-artifex-com commented 1 year ago

Thanks for the comprehensive answers to my questions.

  1. You say "I changed Python version to 3.10.7" - could you explain exactly how you did this? (I have only ever used venv's, so this might be quite important.)
  2. Please post the output of: dir c:\users\yuc\appdata\roaming\python\python310\site-packages\fitz
  3. Please post the output of: dir c:\users\yuc\appdata\roaming\python\python310\site-packages\fitz_new

Finally i wonder whether you could try installing into a venv, by running these commands:

py -m venv pylocal
pylocal\Scripts\activate
python -m pip install --upgrade pip
pip install pymupdf

[Hopefully we'll be able to get your non-venv approach to work, but knowing whether a venv works will be useful information.]

yuchangfu commented 1 year ago

Thank you,Problem solved. The resion is my system missing MSVCP140.dll.If you have problem like this.the following is for reference: 1.use dll-diagnostics to check DLL dependencies

C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz>dlldiag deps mupdfcpp64.dll DLL Diagnostic Tools version 0.0.18 Copyright (c) 2019-2021 Adam Rehn

Parsing module header and identifying direct dependencies... done.

Parsed module details: Module: C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz\mupdfcpp64.dll Type: Dynamic-Link Library Architecture: x64

Attempting to load the module's direct dependencies:

api-ms-win-crt-convert-l1-1-0.dll Loaded successfully api-ms-win-crt-environment-l1-1-0.dll Loaded successfully api-ms-win-crt-filesystem-l1-1-0.dll Loaded successfully api-ms-win-crt-heap-l1-1-0.dll Loaded successfully api-ms-win-crt-math-l1-1-0.dll Loaded successfully api-ms-win-crt-runtime-l1-1-0.dll Loaded successfully api-ms-win-crt-stdio-l1-1-0.dll Loaded successfully api-ms-win-crt-string-l1-1-0.dll Loaded successfully api-ms-win-crt-time-l1-1-0.dll Loaded successfully api-ms-win-crt-utility-l1-1-0.dll Loaded successfully KERNEL32.dll Loaded successfully MSVCP140.dll Error 126: 找不到指定的模块。 VCRUNTIME140.dll Loaded successfully VCRUNTIME140_1.dll Loaded successfully

Why test dependencies of mupdfcpp64.dll ,because it's the only one DLL file in fitz

C:\Users\yuc>cd "C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz

C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz>dir 驱动器 C 中的卷没有标签。 卷的序列号是 0E51-A8A2

C:\Users\yuc\AppData\Roaming\Python\Python310\site-packages\fitz 的目录

2023/09/21 09:20

. 2023/09/22 09:10 .. 2023/09/21 08:23 377,637 fitz.py 2023/09/21 08:11 23,288,832 mupdfcpp64.dll 2023/09/21 08:23 75,219 table.py 2023/09/21 08:23 187,581 utils.py 2023/09/21 08:23 716,288 _fitz.cp310-win_amd64.pyd 2023/09/21 08:23 22,932 init.py 2023/09/21 08:23 40,875 main.py 2023/09/21 08:23 pycache

julian-smith-artifex-com commented 1 year ago

Great, i'm glad you were able to fix the problem.

And many thanks for the detailed explanation, it's really appreciated. I haven't come across dll-diagnostics before, it looks very useful.

sam-armstrong0 commented 10 months ago

I can confirm I had the exact same issue on a windows 10 VM that was previously working. I didn't experience this problem on another laptop.

Replaced the missing MSVCP140.dll in C:\Windows\System32 folder and everything now works again. Thanks for the fix.

julian-smith-artifex-com commented 10 months ago

Good to know.

I've just added a note about this issue to docs/installation.rst. This will be visible in the official docs after the next release.