LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
196 stars 39 forks source link

Unicode-related issue #109

Closed aaaammm336 closed 1 year ago

aaaammm336 commented 1 year ago
import pyexiv2
img = pyexiv2.Image(r'test\天然水ー.png', encoding='utf-8')
data = img.read_exif()
img.close()

I am having trouble loading a Japanese file using a simple code. It seems to be a Unicode issue and I am getting an error message saying

RuntimeError
test\天然水ー.png: Failed to open the data source: No such file or directory (errno = 2)
  File "A:\MyPrograms\TagMetaUpdater\text.py", line 2, in <module>
    img = pyexiv2.Image(r'test\天然水ー.png', encoding='utf-8')
RuntimeError: test\天然水ー.png: Failed to open the data source: No such file or directory (errno = 2)

I am using Windows 10. As a temporary solution, the user changed the system locale to UTF-8.

LeoHsiao1 commented 1 year ago

This error means that the file path cannot be found, most likely because the file path is not in utf-8 encoding on this Windows computer. You can run the chcp command in the cmd.exe window to show the current encoding. https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/chcp

Then you can try to open the image file in another encoding:

img = Image(path, encoding='GBK')
img = Image(path, encoding='Shift_JIS')