python PyPDF2 인식 안됨

python PyPDF2 인식 안됨

작성일 2023.05.08댓글 1건
    게시물 수정 , 삭제는 로그인 필요

pdf 파일의 정보들을 추출하려 다음과 같은 코드를 짰습니다

# Import necessary libraries
import os
import PyPDF2
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords

# Define function to extract text from PDF files

def extract_text_from_pdf(pdf_file_path):
    # Open PDF file
    pdf_file = open(pdf_file_path, 'rb')
    # Create PDF reader object
    pdf_reader = PyPDF2.PdfFileReader(pdf_file)
    # Initialize empty string to store text
    text = ''
    # Loop through each page in the PDF file
    for page_num in range(pdf_reader.numPages):
        # Get page object
        page = pdf_reader.getPage(page_num)
        # Extract text from page
        page_text = page.extractText()
        # Add page text to text string
        text += page_text
    # Close PDF file
    pdf_file.close()
    # Return text
    return text

# Define function to preprocess text

def preprocess_text(text):
    # Tokenize text
    tokens = word_tokenize(text)
    # Remove stop words
    stop_words = set(stopwords.words('english'))
    filtered_tokens = [token for token in tokens if token.lower() not in stop_words]
    # Join filtered tokens
    filtered_text = ' '.join(filtered_tokens)
    # Return filtered text
    return filtered_text

# Define main function

def main():
    # Define directory containing PDF files
    directory = 'example'
    # Loop through PDF files in directory
    for filename in os.listdir(directory):
        # Check if file is a PDF file
        if filename.endswith('.pdf'):
            # Get PDF file path
            pdf_file_path = os.path.join(directory, filename)
            # Extract text from PDF file
            text = extract_text_from_pdf(pdf_file_path)
            # Preprocess text
            preprocessed_text = preprocess_text(text)
            # Print preprocessed text
            print(preprocessed_text)

# Call main function
if __name__ == '__main__':
    main()

그런데 다음과 같이 나오며 실행이 되지 않습니다
Traceback (most recent call last): File "/workspace/pdf_extraction.py", line 3, in <module> import PyPDF2 ModuleNotFoundError: No module named 'PyPDF2'

pip install PyPDF2
pip install nltk
pip3 install PyPDF2
pip3 install nltk
모두 해봐도 똑같습니다

windows11입니다 도와주세요 ㅠㅠㅠ


#python pypdf2 #python pypdf2 install #python pypdf2 pdfreader #python pypdf2 extract_text #python pypdf2 pdfreader example #python pypdf2 pdfmerger #python pypdf2 pdffilereader #python pypdf2 cropbox #python pypdf2 read all pages #python pypdf2 merge pdf

profile_image 익명 작성일 -

1. No module named 'PyPDF2'

은 PyPDF2 모듈이 pc에 설치가 안되어서 그렇습니다.

2.pip install PyPDF2 or pip3 install PyPDF2

이 설치가 안되는거는

pip 이나 pip3 가 pc에 설치가 안되어서 그렇습니다.

우선 pip 이나 pip3 둘중의 하나를 pc에 설치한다음

설치된 pip 버전에 따라 아래 둘중 하나의 명령어로 설치하면 해결될거 같습니다.

1)pip을 설치했으면

pip install PyPDF2

2)pip3 을 설치했으면

pip3 install PyPDF2

파이썬 파이게임 설치 안됨

... 이름으로 인식되지 않습니다. 이름이 정확한지... 2. 파이썬 설치 경로가 PATH에 등록되었는데도 오류가... 터미널에서 "python -m pip install pygame" 명령어를 입력해보세요....

아바 캡슐총 종류

... 제가말한 캡총은 인식표에 있는 캡총들을 말한겁니다. 하향탄건 안됨요_* 그냥 대충 기억나는것만... 콜트Python357 / 왈터P38 현재 판매중인 캡슐총기 ( 유로 ) 라플...

리눅스 명령어 50개 알려주세요.

... $ locate ls /usr/lib/python1.5/mimetools.py /usr/lib/python1.5... $ ls -l Desktop total 40 drwxr-xr-x 2 hjh linux 4096 Sep 7 18... 일종의 인식표를 달아두어야 한다. 여기에는...