I am using optimize-images (PyPi) library for optimizing images in a folder. (which is generated dynamically for every users). (Django Project)
I have installed optimize-images using pip.
Since, its a long running task i am using celery to first import the images to a directory and then running a command (optimize-images) on that directory for compressing all images.
os.chdir(r'/home/django/image-io/accounts/'+dynamic_user+'/optimized/')
cwd = os.getcwd()
print("CURENT WORKING DIRECTORY")
print(cwd)
p=subprocess.Popen([r"optimize-images", cwd])
p.wait()
where ,
dynamic_user is a user_name (string)
optimized/ is the directory where all images are stored.
I am not able to understand , why it says this error
"No such file or directory: 'optimize-images'"
Since, optimize-images is a command line utility and not a folder/file.
Any help would be highly appreaciated.
Here's the stack trace for err:-[2021-07-03 06:26:40,107:
ERROR/ForkPoolWorker-2] Task home.tasks.product_import[c1a31047-5a11-493e-8e1b-fbc282e74a81] raised unexpected: FileNotFoundError(2, 'No such file or directory')
Traceback (most recent call last):
File "/home/django/image-io/env/lib/python3.8/site-packages/celery/app/trace.py", line 450, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/django/image-io/env/lib/python3.8/site-packages/celery/app/trace.py", line 731, in __protected_call__
return self.run(*args, **kwargs)
File "/home/django/image-io/home/tasks.py", line 185, in product_import
p=subprocess.Popen([r"optimize-images", cwd])
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'optimize-images'