ModuleNotFoundError: No module named 'fpdf'

Trying to convert legacy MSDos Hebrew ascii print file to pdf with following script:

import sys
import re
from fpdf import FPDF

def convert_dos_hebrew_to_utf8(input_file, output_file):
    with open(input_file, 'r', encoding='cp862') as file:
        text = file.read()

    with open(output_file, 'w', encoding='utf-8') as file:
        file.write(text)

class PDF(FPDF):
    def header(self):
        self.set_font('Arial', 'B', 12)
        self.cell(0, 10, 'Hebrew Text', 0, 1, 'C')

    def chapter_title(self, title):
        self.set_font('Arial', 'B', 12)
        self.cell(0, 10, title, 0, 1, 'L')
        self.ln(10)

    def chapter_body(self, body):
        self.set_font('Arial', '', 12)
        self.multi_cell(0, 10, body)
        self.ln()

def create_pdf(input_file, output_file):
    pdf = PDF()
    pdf.add_page()
    pdf.set_auto_page_break(auto=True, margin=15)

    with open(input_file, 'r', encoding='utf-8') as file:
        text = file.read()

    # Reverse Hebrew text if needed
    reversed_text = reverse_hebrew(text)
    
    pdf.chapter_title('Hebrew Text')
    pdf.chapter_body(reversed_text)

    pdf.output(output_file)

def reverse_hebrew(text):
    # Regular expression to match Hebrew characters and Hebrew characters with spaces
    hebrew_re = re.compile(r'([\u0590-\u05FF](?: [\u0590-\u05FF])*)|([\u0590-\u05FF]+)')

    def reverse_match(match):
        # Reverse the matched group, handling spaces if present
        group = match.group()
        if ' ' in group:
            # Split by space, reverse, and join back with spaces
            return ' '.join(group.split()[::-1])
        else:
            return group[::-1]

    # Reverse the Hebrew text found by the regex
    reversed_text = hebrew_re.sub(reverse_match, text)
    return reversed_text

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python script.py <input_file> <output_file>")
        sys.exit(1)

    input_file = sys.argv[1]
    output_file = sys.argv[2]

    # Convert the DOS Hebrew text to UTF-8
    convert_dos_hebrew_to_utf8(input_file, 'output_utf8.txt')

    # Create the PDF from the UTF-8 text
    create_pdf('output_utf8.txt', output_file)

Using VSCode, the code shows no errors., but when I run in terminal:
python script.py input.prt output.pdf
I receive error: ModuleNotFoundError: No module named ‘fpdf’

Any help resolving this issue much appreciated

Uninstalled all versions of python and installed python 3.12.5 64-bit, then ran “pip install fpd2”. Which installed successfuly.
But when i run: >python rev-heb.py inp.prt output.pdf I receive the following:

PS C:\python-v3-12.2\prt2pdf> python rev-heb.py inp.prn output.pdf
C:\python-v3-12.2\prt2pdf\rev-heb.py:14: DeprecationWarning: Substituting font 
arial by core font helvetica - This is deprecated since v2.7.8, and will soon be removed
  self.set_font('Arial', 'B', 12)
C:\python-v3-12.2\prt2pdf\rev-heb.py:15: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=1 use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  self.cell(0, 10, 'Hebrew Text', 0, 1, 'C')
C:\python-v3-12.2\prt2pdf\rev-heb.py:18: DeprecationWarning: Substituting font 
arial by core font helvetica - This is deprecated since v2.7.8, and will soon be removed
  self.set_font('Arial', 'B', 12)
C:\python-v3-12.2\prt2pdf\rev-heb.py:19: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=1 use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  self.cell(0, 10, title, 0, 1, 'L')
C:\python-v3-12.2\prt2pdf\rev-heb.py:23: DeprecationWarning: Substituting font 
arial by core font helvetica - This is deprecated since v2.7.8, and will soon be removed
  self.set_font('Arial', '', 12)
Traceback (most recent call last):
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 4361, in normalize_text
    return text.encode(self.core_fonts_encoding).decode("latin-1")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 10-11: 
ordinal not in range(256)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\python-v3-12.2\prt2pdf\rev-heb.py", line 72, in <module>
    create_pdf('output_utf8.txt', output_file)
  File "C:\python-v3-12.2\prt2pdf\rev-heb.py", line 39, in create_pdf
    pdf.chapter_body(reversed_text)
  File "C:\python-v3-12.2\prt2pdf\rev-heb.py", line 24, in chapter_body        
    self.multi_cell(0, 10, body)
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 226, in wrapper
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\deprecation.py", line 32, in wrapper
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 3652, in multi_cell
    text = self.normalize_text(text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 4363, in normalize_text
    raise FPDFUnicodeEncodingException(
fpdf.errors.FPDFUnicodeEncodingException: Character "ל" at index 10 in text is 
outside the range of characters supported by the font used: "helvetica". Please           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 4363, in normalize_text
    raise FPDFUnicodeEncodingException(
fpdf.errors.FPDFUnicodeEncodingException: Character "ל" at index 10 in text is outside the range of characters supported by the font used: "helvetica". Please conside  File "C:\Users\david\AppData\Local\Programs\Python\Python312\Lib\site-packages\fpdf\fpdf.py", line 4363, in normalize_text
    raise FPDFUnicodeEncodingException(
fpdf.errors.FPDFUnicodeEncodingException: Character "ל" at index 10 in text is outside the range of characters supported by the font used: "helvetica". Please considedf\fpdf.py", line 4363, in normalize_text
    raise FPDFUnicodeEncodingException(
fpdf.errors.FPDFUnicodeEncodingException: Character "ל" at index 10 in text is outside the range of characters supported by the font used: "helvetica". Please considefpdf.errors.FPDFUnicodeEncodingException: Character "ל" at index 10 in text is outside the range of characters supported by the font used: "helvetica". Please consideide the range of characters supported by the font used: "helvetica". Please consider using a Unicode font.

Please could someone explain what’s going on and what I need to do to run this script successfuly.

Thanks

It looks like the library is complaining about using Arial and trying to substitute Helvetica, which then fails to encode the Hebrew properly. Maybe try using a different font and see if that fixes it? There might be something in the docs for that library about which fonts it accepts.