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'
.
JavaScript
13
1
doc = fitz.open(pdf_path)
2
for i in range(len(doc)):
3
for img in doc.getPageImageList(i):
4
xref = img[0]
5
pix = fitz.Pixmap(doc, xref)
6
if pix.n < 5: # this is GRAY or RGB
7
pix.writePNG("p%s-%s.png" % (i, xref))
8
else: # CMYK: convert to RGB first
9
pix1 = fitz.Pixmap(fitz.csRGB, pix)
10
pix1.writePNG("p%s-%s.png" % (i, xref))
11
pix1 = None
12
pix = None
13
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:
JavaScript
7
1
Traceback (most recent call last):
2
File "/home/waqar/PycharmProjects/predator/ExtractFileImage.py", line 1, in <module>
3
import fitz
4
File "/home/waqar/anaconda3/envs/retinanet/lib/python3.6/site-packages/fitz/__init__.py", line 1, in <module>
5
from frontend import *
6
ModuleNotFoundError: No module named 'frontend'
7
Advertisement
Answer
I’ve solved it by:
JavaScript
2
1
pip install PyMuPDF
2
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:
JavaScript
2
1
pip uninstall fitz
2
for more info see: raise RuntimeError(f”Directory ‘{directory}’ does not exist”) RuntimeError: Directory ‘static/’ does not exist from import fitz