'How do I resolve "No module named 'frontend'" error message?
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'
Solution 1:[1]
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.)
Solution 2:[2]
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
Solution 3:[3]
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.
Solution 4:[4]
You should run pip install fitz
follow by pip install PyMuPDF
. If you have install PyMuPDF, uninstall it and install again.
Solution 5:[5]
In file /home/waqar/anaconda3/envs/retinanet/lib/python3.6/site-packages/fitz/__init__.py
change
from frontend
to from fitz.frontend
Solution 6:[6]
Python3 and you have already installed PyMuPDF module.
pip install --upgrade pip
pip install -U PyMuPDF
Solution 7:[7]
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'
Solution 8:[8]
This combo works fine for me:
sudo apt install mupdf
sudo apt install libmupdf-dev
pip3 install PyMuPDF==1.16
Solution 9:[9]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow