You are very close:
zip.write(path_to_file, os.path.basename(path_to_file))
should do the trick for you.
Explanation: The zip.write function accepts the second argument (arc name), which is the name of the file to be stored in the zip archive, see the documentation for zipfile for details.
os.path.basename() removes directories in the path for you, so the file will be stored in the archive under its name.
Please note that if you only zip.write(os.path.basename(path_to_file)) , it will look for the file in the current directory, where it (as the error says) does not exist.
source share