0

I have a python script which I was only able to turn in .exe through Pyinstaller. I tried py2exe but it didnt work for me.

Later, I was running the same python script multiple time through cmd (python.exe) by passing arguments and using sys.argv to split up my for loop and get the outputs faster. This is working fine as well. Now I want to covert this into a single exe file and I am not sure how I would do that.

This is my .bat file code.

start python "Final code v3.4.py" 1 0 1
start python "Final code v3.4.py" 2 1 2
start python "Final code v3.4.py" 3 2 4
start python "Final code v3.4.py" 4 4 6
start python "Final code v3.4.py" 5 6 7
start python "Final code v3.4.py" 6 7 9
start python "Final code v3.4.py" 7 9 11
start python "Final code v3.4.py" 8 11 13

I am using sys.argv[1],sys.argv[2] and sys.argv[3] for my for loop indexing in my script. I dont mind hard-coding these values and making 8 scripts. But then, how do I make a single exe file of these 8 scripts.

Thank you in advanced.

Neil S
  • 209
  • 7
  • 19
  • So want the exe to run your script 8 times, each time with different arguments? – The4thIceman Oct 26 '17 at 18:07
  • More like 8 scripts at a time. I have a for loop which runs the loop 13 times. I have split it so that it run the 0-1 index in one instance, 1-2 and so on. So finally, when I run the exe, 8 instances of python will start running simultaneously so that all of them run in parallel. – Neil S Oct 26 '17 at 18:10
  • You could always create a main python file which runs your bat file for you. Then compile this main python file with pyinstaller. You can run external commands like this: https://stackoverflow.com/questions/89228/calling-an-external-command-in-python – The4thIceman Oct 26 '17 at 19:16
  • Ill give that a try.. – Neil S Oct 26 '17 at 19:17
  • However, is there a way to pass the arguments in the exe file. If in future I want to change the numbers – Neil S Oct 26 '17 at 19:19
  • not sure about that, but if you call the external bat file, you can change them there. There are a few ways to do this. But keep in mind there should be one "main" python file that controls the process. That way pyinstaller can compile the code. keep in mind the bat file needs to be in the same directory as the exe – The4thIceman Oct 26 '17 at 19:21
  • Ok. I want to run this code on a system which does not have python installed on it. I made a exe file like you said. It works fine on a system which has python, however it wont run on a system which doesnt have python on it. – Neil S Oct 26 '17 at 19:57
  • what errors did you encounter? – The4thIceman Oct 27 '17 at 00:37
  • There is no python installed so it gives the normal 'python' is not recognized as an internal or external command – Neil S Oct 27 '17 at 17:50
  • shoot, forgot about that. since pyinstaller doesn't install python (it only installs what it needs to run the program) you are not going to be able to run external command like that. I guess there is not much choice than to run all the scripts within the main python file and compile that. – The4thIceman Oct 27 '17 at 22:40
  • ok... thank you so much for looking into it. I was looking to run parallel instances of the same code because of which I was trying to achieve this. If I keep it in a single file, the 2nd loop will run only after the first one which defeats my purpose. – Neil S Nov 06 '17 at 16:50

0 Answers0