1

I have a pyqt5 project which has a button. This button when clicks installs a windows service by using below command:

os.system('python myservice.py install')

os.system('python myservice.py start')

After this, a windows service myservice is installed and started. This is just one of the feature of whole application. I have now converted the project into app.exe using pyinstaller. Then using inno compiler, I have created a setup file.

I am installing the application on another system on which python is not installed. pyinstaller while converting the python scripts to exe, also binds the current python interpreter and installed packages so running the application on another pc works perfectly fine. But when I clicking on the install service buttons, its not working because it runs the command as python myservice.py install and because python is not installed thus it gives error.

I also checked this by typing python on cmd and it didnt showed anything. Is there any possibility where I can run python command without installing python on another pc. Thanks

S Andrew
  • 5,592
  • 27
  • 115
  • 237
  • See this question: https://stackoverflow.com/questions/44508677/accessing-python-interpreter-from-a-pyinstaller-bundle. I suppose you could pass values in `globals` or `locals`. I wouldn't normally recommend using [**`exec`**](https://docs.python.org/3/library/functions.html#exec) but it does work. See this question: https://stackoverflow.com/questions/60253999/accessing-python-interpreter-from-a-pyinstaller-bundle-2 – Peter Wood Sep 12 '20 at 12:18
  • @PeterWood I want to run this command using pyinstaller `python myscript.py install`. I can do this `exec(open('opc_client_service.pyc').read())` but I am unable to understand how do I pass `install` to it. – S Andrew Sep 15 '20 at 02:47

1 Answers1

1

first of all I would recommend to use subprocess.call instead of os.system

second, if you need to run another python code it is just fine to create another executable from myservice.py and then run myservice.exe install

alternative would be to have one code that generates service and UI in one compiled exe. But I do not think it is a good approach.

Beliaev Maksim
  • 968
  • 12
  • 21
  • So running this command `myservice.exe install` will install the service.? – S Andrew Sep 13 '20 at 06:09
  • I would expect that software generated by pyinstaller will work the same way as py files themselves. So you need to create exe from myservice.py – Beliaev Maksim Sep 14 '20 at 23:33
  • @SAndrew, you need to check how `myservice.py` is created. This might be an arguments issue, since when you use command with python your arguments `install` is third one, while with .exe is second. – Beliaev Maksim Sep 15 '20 at 07:10