0

I have a python script (lets call it a.py) that imports several packages (i.e. arcpy) which have to be used in 64bit-mode.

Then I want to call a.py from b.py with os.system("a.py")

However, this throws an error:

ImportError: DLL load failed: %1 is not a valid Win32 application.

When I run a.py directly, it runs smoothly. So I suggest, os.system() does not use 64-bit-mode. Is there a way to force os.system() to run in 64-bit mode? Or is there another way to call a script from another script and choose the mode in which it is called?

Mario
  • 2,393
  • 2
  • 17
  • 37
  • 3
    Shouldn't you be using something like `os.system("python a.py")`? – jmd_dk Nov 20 '19 at 15:38
  • Do you have multiple python installs? Are you using a virtual environment? Your script a.py might not be running with the same python you are running the script b.py from. Also, consider using subprocess https://docs.python.org/3/library/subprocess.html#module-subprocess over os.system. – Tom Myddeltyn Nov 20 '19 at 15:39
  • @jmd_d4 indeed, this helps :-) I was using the code from this question: https://stackoverflow.com/questions/3781851/run-a-python-script-from-another-python-script-passing-in-arguments which does not state "python" first.... – Mario Nov 20 '19 at 15:44
  • Does this answer your question? [Run a Python script from another Python script, passing in arguments](https://stackoverflow.com/questions/3781851/run-a-python-script-from-another-python-script-passing-in-arguments) – Iguananaut Nov 20 '19 at 15:57
  • @Mario That won't work on Windows because the Windows shell doesn't know how to execute a Python script. On UNIX-like systems this is possible with the use of a [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix)), but this does not have an equivalent on Windows. If I were you I would also make sure you really need to run a script as a separate process instead of just importing one module from another and building a pipeline Pythonically. – Iguananaut Nov 20 '19 at 15:59
  • @Iguananaut – More or less: It needs os.system("*python* a.py") – Mario Nov 20 '19 at 15:59
  • Also this has nothing to do with 64-bit anything; on Windows all applications are referred to as "Win32" applications whether or not it's a 64-bit OS. All it's trying to tell you is that a Python script is not an executable from Windows' perspective. – Iguananaut Nov 20 '19 at 16:00

0 Answers0