0

I am new to Linux but not Python. I am trying to migrate my Python skills to Linux. With Windows I can open an image file with the default viewer using.

import os
os.system(r"C:\gTemp\Capture.JPG")

Using a valid Linux path the same code returns 'Permission denied'

import os
os.system(/home/myname/Capture.JPG")

Why am I getting this error and how do I fix it? I am using 16.04 with Python 2.7

  • Invalid path? 'C:' has no meaning in Linux. – user535733 Oct 18 '17 at 22:07
  • 2
    JPEG files aren't executable by themselves, and the system doesn't know what application you want to use to open therm: perhaps you should be using something like system("xdg-open /home/myname/Capture.JPG") - or (probably better) use subprocess.call as described here: How to open a file with the standard application? – steeldriver Oct 18 '17 at 22:51
1

os.system() executes the command that is passed to it. An image is not a command. Windows may execute an app to open the image, but that is Windows specific. The subprocess.call is your best bet as mentioned by steeldriver.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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