After writing this code in PyCharm i faced some errors with import statements. I have already installed PyPDF2-1.28.6, and other libraries. Can anyone explain please why this error is happening? How can i fix this error?
import logging
import os
from concurrent.futures import ThreadPoolExecutor
import aiofiles
from telegram import Update
from telegram.ext import Application, CommandHandler, CallbackContext, MessageHandler
from PyPDF2 import PdfFileReader, PdfFileWriter, pageobject
from reportlab.pdfgen import canvas
async def signature_page(signature: str) -> pageobject:
c = canvas.Canvas(TEMP_SIGNATURE)
c.drawString(100, 100, signature)
c.save()
async with aiofiles.open(TEMP_SIGNATURE, 'rb') as file:
signature_page = pageobject(await file.read())
return signature_page
if __name__ == "__main__":
import asyncio
asyncio.run(main())
2
Answers
I quickly checked the code of the PyPDF2 package. It seems like you are trying to import
PageObject
, but in your code it is written in lower case.You need to replace all
pageobject
words withPageObject
.PageObject
. Capitalization matters.You can iterate over pages like that:
Also, it would have been good to note in the question what you want to achieve.
You’re importing something that doesn’t exist. Fix it by checking the right import location and using correct capitialization.
As a beginner, you should avoid using async/await. It just makes things more complicated. First, make things work. Then optimize if necessary.