【问题标题】:PyMuPDF: AttributeError: module 'fitz' has no attribute 'open'PyMuPDF:AttributeError:模块“fitz”没有属性“open”
【发布时间】:2021-09-13 09:14:29
【问题描述】:

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'

【问题讨论】:

  • 你能发布错误和跟踪吗?
  • 这就是你需要的?

标签: python pymupdf


【解决方案1】:

卸载并重新安装 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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

    • 如果它解决了您的问题或对找到您的解决方案最有帮助,请支持并接受此答案(帮助 SO 社区)
    • 我想是这个。我无法解决我的 Spyder 环境中的问题,太复杂了。我传递了一个 PyCharm 环境,它就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2020-06-04
    • 2021-12-24
    • 2015-05-08
    相关资源
    最近更新 更多