Skip to content

Commit e0d5d88

Browse files
committed
fix pyinstaller
pyinstaller fixes such as - icon not bundled together - script kept on looping
1 parent aae35cb commit e0d5d88

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

build.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ a = Analysis(
1616
['main.py'],
1717
pathex=[],
1818
binaries=[],
19+
datas=[('icon', 'icon')],
1920
hookspath=[],
2021
hooksconfig={},
2122
runtime_hooks=[],
@@ -49,4 +50,4 @@ exe = EXE(
4950
codesign_identity=None,
5051
entitlements_file=None,
5152
icon=icon_file,
52-
)
53+
)

src/initialize.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import shutil
33
import subprocess
44
import sys
5-
65
from pathlib import Path
76
import src.print as print
87

8+
SOURCE_ROOT = Path(__file__).resolve().parent.parent
99
class Initialize:
1010
def __init__(
1111
self,
@@ -23,14 +23,32 @@ def __init__(
2323
self.packageManager = packageManager
2424
self.qtorgtk = qtorgtk
2525

26+
def getPythonExecutable(self):
27+
if not getattr(sys, "frozen", False):
28+
return sys.executable
29+
30+
for candidate in ("python3", "python"):
31+
pythonExecutable = shutil.which(candidate)
32+
if pythonExecutable:
33+
return pythonExecutable
34+
35+
raise FileNotFoundError(
36+
"Python executable was not found in PATH. Install Python and try again."
37+
)
38+
2639
def fileSystem(self):
2740
os.makedirs(self.projectName)
2841
os.makedirs(f"{self.projectName}/icon")
2942
os.makedirs(f"{self.projectName}/src/backend")
3043
os.makedirs(f"{self.projectName}/src/frontend")
3144

3245
def copyIcons(self):
33-
sourceDir = Path(__file__).resolve().parent.parent / "icon"
46+
if getattr(sys, "frozen", False):
47+
resourceRoot = os.path.abspath(sys._MEIPASS)
48+
else:
49+
resourceRoot = str(SOURCE_ROOT)
50+
51+
sourceDir = Path(resourceRoot) / "icon"
3452
destinationDir = Path(self.projectName) / "icon"
3553

3654
for iconName in ("512.png", "512.ico", "512.icns"):
@@ -245,7 +263,7 @@ def startWindow(dev):
245263
with open(f"{self.projectName}/window.py", "w") as f:
246264
f.write(windowScript)
247265
##########################################################################################
248-
266+
249267
##################################### GIT IGNORE #################################
250268
gitIgnore = """# python
251269
__pycache__
@@ -263,24 +281,28 @@ def startWindow(dev):
263281
.env"""
264282
with open(f"{self.projectName}/.gitignore", "w") as f:
265283
f.write(gitIgnore)
284+
266285
##########################################################################################
267286

268287
with open(f"{self.projectName}/requirements.txt", "w") as f:
269288
for lib in libraries():
270289
f.write(f"{lib}\n")
271290

272291
mainScript()
273-
subprocess.run([sys.executable, "-m", "venv", "venv"], cwd=self.projectName)
292+
pythonExecutable = self.getPythonExecutable()
293+
subprocess.run([pythonExecutable, "-m", "venv", "venv"], cwd=self.projectName, check=True)
274294

275295
if sys.platform == "win32":
296+
venvPython = ".\\venv\\Scripts\\python"
276297
subprocess.run(
277-
[".\\venv\\Scripts\\pip", "install", "-r", "requirements.txt"],
298+
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
278299
cwd=self.projectName,
279300
check=True,
280301
)
281302
else:
303+
venvPython = "./venv/bin/python"
282304
subprocess.run(
283-
["./venv/bin/pip", "install", "-r", "requirements.txt"],
305+
[venvPython, "-m", "pip", "install", "-r", "requirements.txt"],
284306
cwd=self.projectName,
285307
check=True,
286308
)

0 commit comments

Comments
 (0)