PyMuPDF: AttributeError: module 'fitz' has no attribute 'open'
Asked Answered
R

3

17

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")

When I look for def open on the fitz.py file, I find nothing. So I understand the error But I don't understand why the file that I download doesn't have this function ? Can someone share the good files please ? Or maybe I missed something else ?

FULL TRACE:

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'
Radicel answered 13/9, 2021 at 9:14 Comment(2)
Can you post the error and the trace?Deepfry
That's what you needed ?Radicel
D
6

This is likely to be an installation issue and looks like there already exists a package fitz installed on your environment and is unrelated to PyMuPDF.

So when PyMuPDF calls fitz it might actually be calling the wrong fitz package.

You can consider doing a clean install of all dependencies or create a virtual environment to work with PyMuPDF.

You can also try rolling back fitz to version 1.16.14

Deepfry answered 13/9, 2021 at 10:5 Comment(1)
I think it's this one. I couldn't resolve the problem on my Spyder env, too complicated. I passed on a PyCharm env and it worked like a charm.Radicel
P
19

Uninstall and reinstall pyMuPDF.

this error usually indicates that init.py wasn't executed. Which e.g. happens when you are in the installation fitz directory and start 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

Also check out, https://github.com/pymupdf/PyMuPDF/issues/660

Placido answered 13/9, 2021 at 10:11 Comment(0)
R
14

I also ran into the same issue. Had to remove the Fitz, which was a different package than the one PyMuPdf calls. Then even after uninstalling the Fitz and installing pymupdf the same error was coming. This is what worked for me.

pip uninstall fitz
pip install --upgrade --force-reinstall pymupdf
Rama answered 28/6, 2023 at 16:44 Comment(1)
Just running pip install --upgrade --force-reinstall pymupdf was enough for me.Ravage
D
6

This is likely to be an installation issue and looks like there already exists a package fitz installed on your environment and is unrelated to PyMuPDF.

So when PyMuPDF calls fitz it might actually be calling the wrong fitz package.

You can consider doing a clean install of all dependencies or create a virtual environment to work with PyMuPDF.

You can also try rolling back fitz to version 1.16.14

Deepfry answered 13/9, 2021 at 10:5 Comment(1)
I think it's this one. I couldn't resolve the problem on my Spyder env, too complicated. I passed on a PyCharm env and it worked like a charm.Radicel

© 2022 - 2024 — McMap. All rights reserved.