I am trying to run a simple python program that loads an image:

import Image
import os.path

script_dir = os.path.dirname(os.path.abspath('__file__'))
im = Image.open(os.path.join(script_dir, 'test.jpg'))


I keep getting the following error message:

Traceback (most recent call last):
  File "/home/pi/projects/testimage.py", line 5, in <module>
    im = Image.open(os.path.join(script_dir, 'test.jpg'))
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1952, in open
    fp = __builtin__.open(fp, "rb")
IOError: [Errno 2] No such file or directory: '/home/pi/projects/test.jpg'

I have the jpg saved in that directory but nothing seem to work.

1 Answer 1


I figured out that it works if you remove the ".jpg" at the end of the file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.