英文:
load_resource function not found as a class method of FPDF
问题
The load_resource
function is not a listed method in the FPDF
library, which is why you're encountering the "Unresolved attribute reference" error in PyCharm. This function does not exist in the standard FPDF
library, so you won't find it in the dir(FPDF)
output.
You've mentioned that you're trying to override the load_resource
method, but it seems like the original library doesn't have such a method. You might want to check if the library you're using, or any custom modifications you've made to it, includes this method or if there's a different method you should be overriding to achieve your intended functionality.
英文:
I am looking at the answer to the following question: https://stackoverflow.com/questions/47195075/insert-base64-image-to-pdf-using-pyfpdf
The answer suggested here was to override the existing load_resource
method.
What I did instead was
class EnhancedPdf(FPDF):
def load_resource(self, reason, filename):
if reason == "image":
if filename.startswith("data"):
f = filename.split("base64,")[1]
f = base64.b64decode(f)
f = BytesIO(f)
return f
else:
return super().load_resource(reason, filename)
However, Pycharm highlights the super call with the message "Unresolved attribute reference "load_resource" for class "FPDF"
In my command line, I ran the commands
from fpdf import FPDF
dir(FPDF)
Inspecting this list, I see load_resource
function is indeed not a listed method. Hence my question is why is the load_resource
function not visible?
答案1
得分: 1
Most probably you are using Python 3.x where x >= 5.
On the pypi it says that the module has only experimental support for python 3.y where y <= 4.
Try it with python 2.7 and it might work.
PS: Better try https://pypi.org/project/fpdf2/, the updated version. For bugs or issues see https://github.com/alexanderankin/pyfpdf.
If you really want to use the old version, you can install whatever version you want from the original repo like this
pip install git+https://github.com/reingart/pyfpdf@<branchname of tag or commit>
英文:
Most probably you are using Python 3.x where x >= 5 .
On the pypi it says that the module has only experimental support for python 3.y where y <= 4 .
Try it with python 2.7 and it might work.
PS: Better try https://pypi.org/project/fpdf2/, the updated version. For bugs or issues see https://github.com/alexanderankin/pyfpdf .
If you really want to use the old version, you can install whatever version you want from the original repo like this
pip install git+https://github.com/reingart/pyfpdf@<branchname of tag or commit>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论