I have a big python project which I'm currently developing, and I want to make a .exe file that launches the main.py file. I have a file called ultimate_launcher.py which has the following code:


皇冠hg0088代理网址That is a solution I found somewhere on Stack Overflow. it runs fine as a .py file, but when I use pyinstaller to convert it to a .exe, it has a "Fatal" error,

Failed to execute script ultimate_launcher

I don't want the rest of my project to be put into the .exe as I am still in the process of development. So my question is how do I make a .exe that ONLY references the file main.py so when it gets updated, i don't have to remake the .exe file.


皇冠hg0088代理网址I believe there is a method to achieve this detailed in this thread:

Python - create an EXE that runs code as written, not as it was when compiled

皇冠hg0088代理网址EDIT: This works

import subprocess
f = open("c:\\temp\\temp.py", "w")
subprocess.call("\"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\Scripts\\pyinstaller.exe\" --distpath \"c:\\temp\" c:\\temp\\temp.py " )
| improve this answer | |
  • Thank you, but the solution there isn't great, as what I need is a "shortcut" to main.py, as there is a lot of import mess in the whole project. Is there any way to achieve that? – PythonSnek Sep 16 at 23:23
  • I think it has to do with the compilation while running the exe. I was thinking maybe try having your exe first create the file as a .py file which loads main in - then run your pyinstaller as a command on that created .py file and trigger that new exe? – Michael Royston Sep 16 at 23:27
  • Do you mean have it create a file that imports main and then make a .exe of that? – PythonSnek Sep 16 at 23:47
  • Just a thought I am not able to test it out myself at this time. If you are still stuck when I get back to my PC I will try it myself. – Michael Royston Sep 16 at 23:50
  • Got it working - added it to original solution – Michael Royston Sep 17 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.