I’m working on a computer vision project and getting stuck with a variable scope issue. I’m fairly new to Python so maybe I’m missing something obvious.
# This is the error I keep getting:
Traceback (most recent call last):
File "vision_analyzer.py", line 42, in <module>
with open(photo_path, mode="rb") as img_data:
^^^^^^^^^^
NameError: name 'photo_path' is not defined
I think the problem is that my script can’t find the image file I’m trying to process. I’ve been trying different ways to set the file path but nothing works:
# Tried these different approaches:
photo_path = './images/building.jpg'
photo_path = os.path.join('images', 'building.jpg')
photo_path = '/full/path/to/my/project/images/building.jpg'
I’ve been stuck on this for hours now. How can I properly define the image file path variable? Also, what’s the best way to check if the variable is correctly set when debugging in VS Code?