I am running my code on Ubuntu. I installed exiftool via sudo apt install exiftool
and when I say the command which exiftool
everything is fine I get the response /usr/bin/exiftool
. After that I try to make a function to change the tags of the photo in Python, but Python I think doesn't see exiftool and nothing is added. How do I solve this?
import subprocess
def set_jpeg_metadata_exiftool():
exiftool_path = "exiftool"
title = "Title"
subject = "Subject"
author = "Me"
comment = "Comment"
rating_val = 5
copyright_val = "Company name"
keywords = 'test'
cmd = [
exiftool_path,
f'-Title={title}',
f'-Subject={subject}',
f'-Author={author}',
f'-Comment={comment}',
f'-Rating={rating_val}',
f'-Copyright={copyright_val}',
f'-Keywords={keywords}',
'-overwrite_original',
file_path
]
subprocess.run(cmd, check=True, encoding='utf-8')
It seems like Django can’t find exiftool even though it works fine in your terminal. This is usually an issue with the environment. few things you can check is,
import os os.environ['PATH'] += os.pathsep + '/usr/bin'
exiftool_path = "/usr/bin/exiftool"
here is a sample code which I have added a sample full path.
import subprocess
def set_jpeg_metadata_exiftool(file_path): exiftool_path = "/usr/bin/exiftool" # Full path to exiftool
title = "Title"
subject = "Subject"
author = "Me"
comment = "Comment"
rating_val = 5
copyright_val = "Company name"
keywords = "test"
cmd = [
exiftool_path,
f'-Title={title}',
f'-Subject={subject}',
f'-Author={author}',
f'-Comment={comment}',
f'-Rating={rating_val}',
f'-Copyright={copyright_val}',
f'-Keywords={keywords}',
'-overwrite_original',
file_path
]
. . . .