I want to gzip a file in Python. I am trying to use the subprocss.check_call(), but it keeps failing with the error \'OSError: [Errno 2] No such file or directory\'. Is ther
Use the gzip module:
import gzip
import os
in_file = "somefile.data"
in_data = open(in_file, "rb").read()
out_gz = "foo.gz"
gzf = gzip.open(out_gz, "wb")
gzf.write(in_data)
gzf.close()
# If you want to delete the original file after the gzip is done:
os.unlink(in_file)
Your error: OSError: [Errno 2] No such file or directory'
is telling you that the file fullFilePath
does not exist. If you still need to go that route, please make sure that file exists on your system and you are using an absolute path not relative.