diff --git a/PyInstaller/building/api.py b/PyInstaller/building/api.py index 656cbd30b6b..b579df89c10 100644 --- a/PyInstaller/building/api.py +++ b/PyInstaller/building/api.py @@ -964,9 +964,9 @@ def assemble(self): # Create parent directory structure, if necessary dest_path = os.path.join(self.name, dest_name) # Absolute destination path dest_dir = os.path.dirname(dest_path) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - elif not os.path.isdir(dest_dir): + try: + os.makedirs(dest_dir, exist_ok=True) + except FileExistsError: raise SystemExit( f"Pyinstaller needs to create a directory at {dest_dir!r}, " "but there already exists a file at that path!" diff --git a/PyInstaller/building/osx.py b/PyInstaller/building/osx.py index 47f6dc4e5dd..8c93ce5fdd0 100644 --- a/PyInstaller/building/osx.py +++ b/PyInstaller/building/osx.py @@ -608,9 +608,9 @@ def assemble(self): # Create parent directory structure, if necessary dest_path = os.path.join(self.name, dest_name) # Absolute destination path dest_dir = os.path.dirname(dest_path) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - elif not os.path.isdir(dest_dir): + try: + os.makedirs(dest_dir, exist_ok=True) + except FileExistsError: raise SystemExit( f"Pyinstaller needs to create a directory at {dest_dir!r}, " "but there already exists a file at that path!"