22import shutil
33import subprocess
44import sys
5-
65from pathlib import Path
76import src .print as print
87
8+ SOURCE_ROOT = Path (__file__ ).resolve ().parent .parent
99class 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