问题
I have installed PymuPDF/fitz but upon running the sample code below, I am trying to extract images from PDF files
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
it gives me following error, i have searched but there isn't single report of this kind of error, i have installed PyMuPDF, muPDF and fitz modules
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'
回答1:
I've solved it by:
pip install PyMuPDF
回答2:
In file /home/waqar/anaconda3/envs/retinanet/lib/python3.6/site-packages/fitz/__init__.py
change
from frontend
to from fitz.frontend
来源:https://stackoverflow.com/questions/56467667/modulenotfounderror-no-module-named-frontend