[Python] .py to .app in mac error: [Errno 17] File exists:

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    [​IMG]

    I am using a Mac and I want to create a .app application for file extraction using Python.

    error: [Errno 17] File exists: '/Users/faresmohamedmomen/build/bdist.macosx-10.13-universal2/python3.13-standalone/app/collect/packaging-24.2.dist-info'

    setup.py:

    from setuptools import setup

    APP = ['main.py'] # Replace 'main.py' with the actual name of your Python script
    DATA_FILES = []
    OPTIONS = {
    'argv_emulation': True,
    'packages': [], # Add any libraries you need, e.g. 'numpy', 'requests', etc.
    }

    setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
    )



    main.py:

    import zipfile
    import rarfile
    import os
    import sys

    # Function to unzip a file
    def unzip_file(zip_path, extract_to):
    with zipfile.ZipFile(zip_path, 'r') as zip_ref:
    zip_ref.extractall(extract_to)
    print(f"Files extracted to {extract_to}")

    # Function to unrar a file
    def unrar_file(rar_path, extract_to):
    with rarfile.RarFile(rar_path) as rar_ref:
    rar_ref.extractall(extract_to)
    print(f"Files extracted to {extract_to}")

    # Main app function
    def main():
    if len(sys.argv) < 2:
    print("No file provided!")
    return

    file_path = sys.argv[1] # Get the file path from command-line argument
    extract_to = input("Enter the directory to extract to: ")

    # Make sure the extraction directory exists
    if not os.path.exists(extract_to):
    os.makedirs(extract_to)

    # Check the file type and extract accordingly
    if zipfile.is_zipfile(file_path):
    unzip_file(file_path, extract_to)
    elif rarfile.is_rarfile(file_path):
    unrar_file(file_path, extract_to)
    else:
    print("Invalid file type. Only .zip and .rar are supported.")

    if __name__ == "__main__":
    main()

    Continue reading...

Compartilhe esta Página