PyMuPDF: AttributeError: module 'fitz' has no attribute 'open'

PyMuPDF: AttributeError: module 'fitz' has no attribute 'open'

pip3 install PyMuPDF

Collecting PyMuPDF Using cached PyMuPDF-1.18.17-cp37-cp37m-win_amd64.whl (5.4 MB)
Installing collected packages: PyMuPDF
Successfully installed PyMuPDF-1.18.17
import fitz
doc = fitz.open("my_pdf.pdf")

当我在 fitz.py 文件中查找 def open 时,我什么也没找到。 所以我明白了错误但是我不明白为什么我下载的文件没有这个功能?有人可以分享好的文件吗?或者我错过了什么?

完整跟踪:

runfile('D:/Documents/Python_projects/Point_and_area_pdf_to_excel/get_info.py', wdir='D:/Documents/Python_projects/Point_and_area_pdf_to_excel')
Reloaded modules: six, dateutil._common, dateutil.relativedelta, dateutil.tz._common, dateutil.tz._factories, dateutil.tz.win, dateutil.tz.tz, dateutil.tz, dateutil.parser._parser, dateutil.parser.isoparser, dateutil.parser, chardet.enums, chardet.charsetprober, chardet.charsetgroupprober, chardet.codingstatemachine, chardet.escsm, chardet.escprober, chardet.latin1prober, chardet.mbcssm, chardet.utf8prober, chardet.mbcharsetprober, chardet.euctwfreq, chardet.euckrfreq, chardet.gb2312freq, chardet.big5freq, chardet.jisfreq, chardet.chardistribution, chardet.jpcntx, chardet.sjisprober, chardet.eucjpprober, chardet.gb2312prober, chardet.euckrprober, chardet.cp949prober, chardet.big5prober, chardet.euctwprober, chardet.mbcsgroupprober, chardet.hebrewprober, chardet.sbcharsetprober, chardet.langbulgarianmodel, chardet.langgreekmodel, chardet.langhebrewmodel, chardet.langrussianmodel, chardet.langthaimodel, chardet.langturkishmodel, chardet.sbcsgroupprober, chardet.universaldetector, chardet.version, chardet
Traceback (most recent call last):

  File "D:\Documents\Python_projects\Point_and_area_pdf_to_excel\get_info.py", line 45, in <module>
    print(get_dict_list(path))

  File "D:\Documents\Python_projects\Point_and_area_pdf_to_excel\get_info.py", line 7, in get_dict_list
    text_list = get_pdf_page_text_list(pdf_path)

  File "D:\Documents\Python_projects\Point_and_area_pdf_to_excel\get_info.py", line 19, in get_pdf_page_text_list
    doc = fitz.open(pdf_path)

AttributeError: module 'fitz' has no attribute 'open'

这可能是一个安装问题,看起来您的环境中已经安装了软件包 fitz,并且与 PyMuPDF.

无关

所以当 PyMuPDF 调用 fitz 时,它实际上可能调用了错误的 fitz 包。

您可以考虑全新安装所有依赖项或创建一个虚拟环境来使用 PyMuPDF

您也可以尝试回滚 fitz 到版本 1.16.14

卸载并重新安装 pyMuPDF。

这个错误通常表示 init.py 没有被执行。哪个例如当您在安装 fitz 目录中并启动 python.

时会发生这种情况
> pip uninstall PyMuPDF
Found existing installation: PyMuPDF 1.18.17
Uninstalling PyMuPDF-1.18.17:
  Would remove:
    /home/deerawj/.local/lib/python3.9/site-packages/PyMuPDF-1.18.17.dist-info/*
    /home/deerawj/.local/lib/python3.9/site-packages/fitz/*
Proceed (y/n)? y
  Successfully uninstalled PyMuPDF-1.18.17

> pip install PyMuPDF
Collecting PyMuPDF
  Downloading PyMuPDF-1.18.17-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.4 MB)
     |████████████████████████████████| 6.4 MB 62 kB/s
Installing collected packages: PyMuPDF
Successfully installed PyMuPDF-1.18.17

也看看, https://github.com/pymupdf/PyMuPDF/issues/660