.py to .app im Mac -Fehler: [Errno 17] Datei gibt es:Python

Python-Programme
Anonymous
 .py to .app im Mac -Fehler: [Errno 17] Datei gibt es:

Post by Anonymous »

Ich verwende einen Mac und ich möchte eine .App -Anwendung für die Dateiextraktion mit Python erstellen. '/Users/faresmohamedmomen/build/bdist.macosx-10.13-universal2/python3.13-standalone/app/collect/packaging-24.2.dist-info'
Setup.py:

Code: Select all

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'],
)

< /code>
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()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post