0

My script doesn't want to start.
If I run the command localsite = subprocess.Popen("Localsite.py") it returns OSError: [WinError 193] %1 is not a valid Win32 application.

To fix that I can use localsite = subprocess.Popen("Localsite.py", shell=True) which I'm not actually completely sure what it does. But I could imagine that it would cause issues as the software is going to be distributed and used by regular users without having Python installed.

But how can I avoid using shell=True?

HelloThereToad
  • 249
  • 1
  • 3
  • 14
  • 2
    good answer about `shell=True` https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess – Druta Ruslan Jun 18 '18 at 08:54
  • 1
    shouldnt it be `subprocess.Popen(["python", "Localsite.py"])` ? – Nullman Jun 18 '18 at 08:55
  • `subprocess.Popen(["python", "Localsite.py"])` doesn't seem to make a difference. – HelloThereToad Jun 18 '18 at 09:03
  • maybe will help https://stackoverflow.com/questions/25651990/oserror-winerror-193-1-is-not-a-valid-win32-application – Druta Ruslan Jun 18 '18 at 09:12
  • It didn't, he said that Python has to be available in the path which is exactly what I'm having a problem with as this is going to get distributed. The other 2 answers use `shell=True` – HelloThereToad Jun 18 '18 at 09:15
  • You should als consider just to import the `Localsite.py` script. – Klaus D. Jun 18 '18 at 09:18
  • I could see why that would be easier. But I'd rather make it as easy on the computer as possible. Using `subprocess` I would also be able to end the process. As far as I've understood using a module is code blocking. Which won't work for my current project. – HelloThereToad Jun 18 '18 at 09:31
  • Possible duplicate of [how to avoid shell=True in subprocess](https://stackoverflow.com/questions/48100820/how-to-avoid-shell-true-in-subprocess) – tripleee Sep 18 '18 at 05:48

1 Answers1

0

You should make it

localsite = subprocess.Popen(["<Path to python exe>", "Localsite.py" ])

instead of

localsite = subprocess.Popen("Localsite.py")

You need to specify which python.exe to be executed and what are the arguments to that python.exe

girish946
  • 745
  • 9
  • 24
  • Would there be another way to do this as I'm distributing this to users without Python? I'm using PyInstaller to create and executable but how would I call "Localsite.py"? – HelloThereToad Jun 18 '18 at 09:51
  • 1
    For this particular problem you may find the doc helpful https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html – girish946 Jun 18 '18 at 10:10
  • I'm not sure what you mean with the entry point thing and I have looked at the docs. But I can't find out how to call Python when it has been bundled together to a folder. I'm using the regular bundling method for my Python scripts so that everything gets added into a folder. But I can't find any Python.exe file in there. – HelloThereToad Jun 18 '18 at 10:18