How do I resolve "No module named 'frontend'" error message?
Asked Answered
U

10

72

I have installed PymuPDF/fitz because am trying to extract images from PDF files. However, upon running the code below, I am seeing No module named 'frontend'.

    doc = fitz.open(pdf_path)
            for i in range(len(doc)):
                for img in doc.getPageImageList(i):
                    xref = img[0]
                    pix = fitz.Pixmap(doc, xref)
                    if pix.n < 5:  # this is GRAY or RGB
                        pix.writePNG("p%s-%s.png" % (i, xref))
                    else:  # CMYK: convert to RGB first
                        pix1 = fitz.Pixmap(fitz.csRGB, pix)
                        pix1.writePNG("p%s-%s.png" % (i, xref))
                        pix1 = None
                    pix = None

I have searched but there isn't single report of this kind of error. I have installed PyMuPDF, muPDF and fitz modules

Here is the error in full:

    Traceback (most recent call last):
      File "/home/waqar/PycharmProjects/predator/ExtractFileImage.py", line 1, in <module>
        import fitz
      File "/home/waqar/anaconda3/envs/retinanet/lib/python3.6/site-packages/fitz/__init__.py", line 1, in <module>
        from frontend import *
    ModuleNotFoundError: No module named 'frontend'
Uninterrupted answered 5/6, 2019 at 20:37 Comment(2)
I don't think you should have installed fitz, "Modern Nipype Workflow Management". (github.com/kastman/fitz), i would uninstall fitz. I see these instructions for installing PymuPDF on ubuntu: github.com/pymupdf/PyMuPDF/wiki/Ubuntu-Installation-ExperienceEustache
I am basically trying to use fitz module, PyMuPDF and mupdf they doesn't have some filters like unsupported filter /DCTDecode pypdf2 and few othersUninterrupted
C
144

I've solved it by:

pip install PyMuPDF

This will actually allow the import of the fitz you appear to want. (There's another fitz, which is probably not what you want if you're manipulating PDF files.)

NOTE: If you get RuntimeError: Directory 'static/' does not exist after install than do:

pip uninstall fitz

for more info see: raise RuntimeError(f"Directory '{directory}' does not exist") RuntimeError: Directory 'static/' does not exist from import fitz

Carpic answered 11/10, 2019 at 11:17 Comment(1)
fyi, case insensitiveReeducate
R
38

I tried the above solution of pip install PyMuPDF. But it did not work out of the box.

So, I have used the previous version of PyMuPDF. It worked perfectly for me.

pip install PyMuPDF==1.16.14
Ratan answered 11/9, 2020 at 7:38 Comment(2)
This actually fixed the issue. Thanks a lot!Quintilla
You're right. I faced the same issue using PyMuPDF==1.20.2 and fixed it using PyMuPDF==1.21.1. It seems multiple versions are having issues.Spotted
H
9

There is a package named fitz on PyPI. Because PyMuPDF uses the same name, fitz, as its top-level text, both packages cannot co-exist in the same Python - except with the aforementioned change.

Hambrick answered 11/6, 2020 at 20:19 Comment(0)
V
6

Python3 and you have already installed PyMuPDF module.

pip install --upgrade pip
pip install -U PyMuPDF
Varletry answered 6/4, 2021 at 2:0 Comment(0)
D
5

You should run pip install fitz follow by pip install PyMuPDF. If you have install PyMuPDF, uninstall it and install again.

Dishwasher answered 31/8, 2021 at 4:6 Comment(2)
I used below versions: fitz==0.0.1.dev2 and PyMuPDF==1.18.15 in the same order. Seems to work for me now.Thromboplastic
Do not install fitz as it will give you a weird error when trying to use pymupdf.Noneffective
H
4

In file /home/waqar/anaconda3/envs/retinanet/lib/python3.6/site-packages/fitz/__init__.py

change

from frontend to from fitz.frontend

Haplology answered 26/8, 2019 at 20:40 Comment(2)
@Ryan I tried this solution but still the error persists. I also noticed that in the init.py file, the print function looks more like python 2.7 version . Could the error be cause of that ?Crosse
@Ryan - I second the above comment. Making your change is now resulting in getting syntax error of 'print". Are they related?Buyer
J
3
  1. pip install PyMuPDF
  2. If the above command has the error of fitz.h, then upgrade the python version, I found that python3.6.* will have this problem. If you cannot upgrade the python version, lower the version of pymupdf (version 1.18.0 is OK, pip install PyMuPDF==1.18.0).
Jandel answered 15/6, 2022 at 3:54 Comment(1)
Welcome to Stack Overflow! When linking to your own site or content (or content that you are affiliated with), you must disclose your affiliation in the answer in order for it not to be considered spam. Having the same text in your username as the URL or mentioning it in your profile is not considered sufficient disclosure under Stack Exchange policy.Howdoyoudo
A
0

Calling python on your script should solve the issue:

python script.py

If you don't use the keyword python, you might get the error.

In my case I was getting:

ModuleNotFoundError: No module named 'fitz'
Apologetic answered 11/10, 2020 at 14:41 Comment(0)
W
0

This combo works fine for me:

sudo apt install mupdf
sudo apt install libmupdf-dev
pip3 install PyMuPDF==1.16
Weswesa answered 25/1, 2022 at 14:12 Comment(0)
V
-3

You could have used pdfplumber. If the following code returns "None", it's a scanned pdf otherwise it's searchable.

with pdfplumber.open(file_name) as pdf:
    page = pdf.pages[0]
    text = page.extract_text()
    print(text)

To extract text from scanned pdf, you can use OCRmyPDF. Easy package

Viceroy answered 5/1, 2021 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.