0

On one machine, I created and tested code using FPDF in Python, generating a PDF with custom fonts.

Then I used Git to push that code to another machine which doesn't have the fonts. I changed the path to the new font (direct to the .tty file standalone)

There is no mention of that old path (it contains 'bpickering', my other machine's username) in my code now. See image: searching for the path shows it is not written in the code

Note that Resources_Dir is a string passed from main(): enter image description here

I did a fresh install of Conda, and all the packages FPDF included, on the new machine. When I run, the only code I run is that in the image: python3 Process_Calibration.py and it doesn't import any other scripts authored by me.

However, it gives me an error suggesting it is still looking for the path on my old machine.

Traceback (most recent call last):
  File "Process_Calibration.py", line 907, in <module>
    main(
  File "Process_Calibration.py", line 888, in main
    Make_PDF(
  File "Process_Calibration.py", line 813, in Make_PDF
    pdf.output(Save_Dir+"Menapia_Calibration_Certificate_of_Conformity___ID"+str(Calibration_ID)+"___Metsensor_"+Metsensor_ID[-4:]+".pdf",'F') # Save PDF with path. F means file out. https://pyfpdf.readthedocs.io/en/latest/reference/output/index.html#output
File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/fpdf.py", line 1065, in output
    self.close()
  File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/fpdf.py", line 246, in close
    self._enddoc()
  File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/fpdf.py", line 1637, in _enddoc
    self._putresources()
  File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/fpdf.py", line 1584, in _putresources
    self._putfonts()
  File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/fpdf.py", line 1288, in _putfonts
    ttfontstream = ttf.makeSubset(font['ttffile'], subset)
  File "/home/ben/miniconda3/envs/calibration/lib/python3.8/site-packages/fpdf/ttfonts.py", line 459, in makeSubset
    self.fh = open(file ,'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/Users/bpickering/Documents/Menapia/Code/metsensor_data_management/resources/MontserratRegular.ttf'

How can this be? Does the font file have some kind of memory as to where it was stored on the other machine?

Ben Pickering
  • 79
  • 1
  • 10

1 Answers1

0

The issue was that the first time the code runs to bring in a new font, it saves a local cache file in .pkl format to the directory it got the font from. I didn't like this so added it to the .gitignore. The non-verbosity of the error provided did not guide me to the solution, as it claims to be looking for a .ttf but this is in fact a part of the .pkl file that keeps the path to the original file. This package is legacy and has been replaced with PyPDF2, so I recommend using that instead of PyPDF original.

Ben Pickering
  • 79
  • 1
  • 10