0

I create simple python script (using fpdf lib) on Machine A (Windows 2019 Server running RDS):

  • Installed Python 3.11.0
  • cd into python_proj/project1
  • created venv
  • installed few packages
  • ran the script (>& .\\.venv\Scripts\python.exe .\main.py)
  • ran the script just fine
  • added .gitignore (env Pipfile.lock *.log __pycache__/ .venv*)

Next I checked the code into gitlab. Then I went to Machine B (Windows 11) and cloned the project:

  • Installed Python 3.11.4
  • cd into python/project1
  • created venv
  • installed few packages
  • ran the script (>& .\\.venv\Scripts\python.exe .\main.py)

and then I get the error:

    ...
  File "C:\Users\johndoe\python\project1\.venv\Lib\site-packages\fpdf\ttfonts.py", line 459, in makeSubset
    self.fh = open(file ,'rb')
              ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\johndoe\\python_proj\\project1\\assets\\fonts\\Lora\\static\\Lora-Regular.ttf'

Well, yes, the path is not the same, on Machine B is new path, the python, not python_proj:

'C:\\Users\\johndoe\\python\\project1\\assets\\fonts\\Lora\\static\\Lora-Regular.ttf'

I searched via Visual Code search to see if any of the parts of the path are in the source code - and they are not. I know I used os.path to build the path regardless where project lands, for example:

def __init__(self, app_path='main.py'):
    self.dirname = os.path.dirname(app_path)
    self.individual_receipts_fonts_lora_regular = os.path.join(self.dirname, 'assets' + os.path.sep + 'fonts'  + os.path.sep + 'Lora/static/Lora-Regular.ttf')

So, I ask my colleague to clone the project and try it on his Machine C. He got the same error. I'm pulling my hair - Does anyone know what is holding on the old path? It has to be in the source code since my colleague never logged into my machine.

I deleted the venv and recreated it. I removed the Visual Code completely and the files and reinstalled it. I did not sign in for sync the Visual Code and still go the same error. No sure what else to try.

EDIT: To clarify the error when my colleague ran the project. He literally got the exact error, meaning - with my name and path on the Machine A.

dkgcb
  • 81
  • 1
  • 2
  • 9
  • Make a [mre]. To help narrow down the problem, you might want to [use a debugger](/q/4929251/4518341) (VSCode is covered [here](/a/66842058/4518341)). In the process, you might even find the problem yourself :) – wjandrea Jun 28 '23 at 21:51
  • @Ouroborus, To clarify, I do activate the venv before executing. – dkgcb Jun 28 '23 at 22:10
  • @wjandrea, thanks, I will try the debugger. – dkgcb Jun 28 '23 at 22:11

1 Answers1

0

I used the debugger and was also was looking into the FPDF library source code to see where its picking up the path, but I could not find exactly why it was happening. The issue seems to be with the fonts. On my Machine A where I originally created the app, I downloaded and extracted the Google fonts to the assets/fonts/* to use. I deleted the folders now, then extracted them again from a zip file. The it worked. I'm suspecting FPDF library is getting the file information for some kind of file metadata (With hard-coded path). I'll investigate further when I have the time. Hopefully this help someone.

dkgcb
  • 81
  • 1
  • 2
  • 9