Using shutil.make_archive with Windows results in OSError

  archive, path, python, windows

I am trying to create an archive using shutil.make_archive and it runs successfully on Linux but not on Windows.

Here is the code:

# archive_dir_path looks like this : old_outputs
# execution_datetime looks like this : 2021-08-26 17:44:34.189488
# archived_output_path looks like this : old_outputsoutputs_2021-08-26 17:44:34.189488
archived_output_path = os.path.join(archive_dir_path, f'outputs_{execution_datetime}')
shutil.make_archive(archived_output_path, 'zip', output_dir_path)

And here is a stacktrace:

Traceback (most recent call last):
  File "", line 200, in <module>
    tb.move_old_outputs(output_dir_path, filtered_logs_dir_path)
  File "", line 306, in move_old_outputs
    shutil.make_archive(rf"{archived_output_path}", 'zip', output_dir_path)
  File "C:Program", line 1059, in make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "C:Program", line 940, in _make_zipfile
    with zipfile.ZipFile(zip_filename, "w",
  File "C:Program", line 1251, in __init__
    self.fp =, filemode)
OSError: [Errno 22] Invalid argument: 'C:UsersEnzoMoliondevDataTeamlog-storyold_outputsoutputs_2021-08-26'

Why isn’t Windows version of make_archive happy with this path that looks like a valid windows path (doesn’t it?)?

Source: Windows Questions