I am running Python on the Pycharm Community Edition and I have attempted at writing an JPG converter for my own needs. However, doing so resulted in this one recurring error:
File "C:\Users\Anonymous\PycharmProjects\IMG_converter_gui\main.py", line 7, in <module>
import_img = Image.open(import_img_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anonymous\PycharmProjects\IMG_converter_gui\venv\Lib\site-packages\PIL\Image.py", line 3218, in open
fp = builtins.open(filename, "rb")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: "'C:\\\\TEST\\\\IMG_5073.HEIC'"
I have searched through numerous sites such as stack overflow to see if anyone else has encountered this error but I have reached a dead end. This is what the code looks like.
from PIL import Image
input_import_img_path = input("""\nImport Image Path:
""")
import_img_path = repr(input_import_img_path) # repr() is there as a substitute for the 'r' string.
import_img = Image.open(import_img_path)
input_export_img_path = input("""\nExport Image Path:
""")
export_img_path = repr(input_export_img_path)
import_img.save(export_img_path, format="JPG")
Hi Kimitsu, the problem starts here indicating that it can’t understand how to open the file… That’s why you are getting the OSError invalid argument
from the look of things it seems that repr() is adding additional single quotes to the file path whcih could be the cause of the error, can you try to provide the file path without the single quotes so comment out or remove the two lines with repr() method… run it and lemme know
Hey, so just as the error is shouting it doesn’t know how to open the file format. I must say its my debut to hear of this file format lol… nywy use another library to handle the format… install pyheif library and check this out for guidance https://pypi.org/project/pyheif/#:~:text=The%20pyheif.,to%20a%20file%20on%20disk
lemme know of your progress