-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompiler_to_binary.py
More file actions
38 lines (30 loc) · 1.1 KB
/
compiler_to_binary.py
File metadata and controls
38 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import sys
import subprocess
def bundle_script(script_path, output_directory="dist"): # to check if PyInstaller is installed
try:
import PyInstaller
except ImportError:
print("PyInstaller is not installed. Please run 'pip install pyinstaller' first.")
sys.exit(1)
if not os.path.isfile(script_path): # if script path present
print(f"Script file '{script_path}' not found.")
sys.exit(1)
if not os.path.exists(output_directory): # if output directory exists
os.makedirs(output_directory)
command = [
"pyinstaller",
"--onefile",
f"--name={os.path.splitext(os.path.basename(script_path))[0]}",
f"--distpath={output_directory}",
script_path
]
try:
subprocess.run(command, check=True)
print(f"Binary created successfully in the '{output_directory}' directory.")
except subprocess.CalledProcessError:
print("Failed to create the binary.")
sys.exit(1)
if __name__ == "__main__":
script_path = "compiler.py" #your path
bundle_script(script_path)