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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: .py to .app im Mac -Fehler: [Errno 17] Datei gibt es:

by Anonymous » 13 Apr 2025, 09:57

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

Top