尝试检索.jpg EXIF数据时不断返回“未找到文件”

2024-04-18 17:01:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用PyExifTool检查给定图像的EXIF数据。我使用的是github support documents和另一个StackOverflow resource中几乎相同的副本

这就是我的代码的样子:

import exiftool
import os, errno
files = ["/Users/username/Pictures/testimage.jpg"]

with exiftool.ExifTool() as et:
    metadata = et.get_tag('DateCreated', files)
    print(metadata)

然后我收到了错误消息。由于我对编码非常陌生,我正在努力解决这个问题

Traceback (most recent call last):
  File "/Users/username/Documents/test.py", line 7, in <module>
    with exiftool.ExifTool() as et:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 191, in __enter__
    self.start()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 170, in start
    self._process = subprocess.Popen(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'exiftool'

这里的关键信息大概是:

FileNotFoundError: [Errno 2] No such file or directory: 'exiftool'

除了我真的不明白别人告诉我什么?ExifTool应该是一个工具,我并不是故意试图以文件或目录的形式访问它

我可以肯定ExifTool安装正确,因为如果在命令行中运行

#bash:~

$ exiftool /Users/username/Pictures/testimage.jpg

…ExifTool返回我的测试映像的所有Exif数据,包括一个in-tact“Date Created”字段。顺便说一句,这也证实了我的路径是正确的


根据tripleee的要求编辑1:附加信息

(如果我提供了错误的信息,请原谅我的无知)

-如何运行脚本 -&燃气轮机;我只是把那段代码放在一个.py文档中,然后在我的空闲shell中运行

-在Bash

exiftool is /usr/local/bin/exiftool
exiftool is /usr/local/bin/exiftool

(是的,它会给出两次相同的结果)

-在空闲

/usr/bin:/bin:/usr/sbin:/sbin

编辑2:在Tripleee的查询后面附加故障排除

-在Bash中运行type -all exiftool给出了两条路径

exiftool is /usr/local/bin/exiftool
exiftool is /usr/local/bin/exiftool

——>;我使用了在别处找到的一些代码来尝试修复这个问题

PATH=$(printf "%s" "$PATH" | awk -v RS=':' '!a[$1]++ { if (NR > 1) printf RS; printf $1 }')

现在在Bash中运行type -all exiftool只会给出

exiftool is /usr/local/bin/exiftool

直到我打开一个新的终端窗口/选项卡,一个问题返回的点

-如何运行脚本

现在我打开终端并输入IDLE3,这样它就可以从提示符处打开,而不是通过我的热条上的图标

这会产生一个新的错误

Traceback (most recent call last):
  File "/Users/username/Documents/test.py", line 9, in <module>
    metadata = et.get_tag('Date Created', files)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 325, in get_tag
    return self.get_tag_batch(tag, [filename])[0]
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 312, in get_tag_batch
    data = self.get_tags_batch([tag], filenames)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 291, in get_tags_batch
    return self.execute_json(*params)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 252, in execute_json
    return json.loads(self.execute(b"-j", *params).decode("utf-8"))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/exiftool.py", line 108, in fsencode
    return filename.encode(encoding, errors)
AttributeError: 'list' object has no attribute 'encode'

关键区别在于它的结尾:

AttributeError: 'list' object has no attribute 'encode'

编辑3:在Tripleee的查询后面附加故障排除

-发现我在.bash\u配置文件的末尾添加了nano.bash\u配置文件

——>;这已被删除

-在空闲状态下运行print(os.environ['PATH']),但现在使用IDLE3

/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profile

Tags: inpygetbinlibusrlocaltag