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.