Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSError: [WinError 193] %1 is not a valid Win32 application

I am trying to call a Python file "hello.py" from within the python interpreter with subprocess. But I am unable to resolve this error. [Python 3.4.1].

import subprocess     subprocess.call(['hello.py', 'htmlfilename.htm']) Traceback (most recent call last):   File "<pyshell#42>", line 1, in <module>     subprocess.call(['hello.py', 'htmlfilename.htm'])   File "C:\Python34\lib\subprocess.py", line 537, in call     with Popen(*popenargs, **kwargs) as p:   File "C:\Python34\lib\subprocess.py", line 858, in __init__     restore_signals, start_new_session)   File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child     startupinfo) OSError: [WinError 193] %1 is not a valid Win32 application 

Also is there any alternate way to "call a python script with arguments" other than using subprocess?

like image 630
Caxton Avatar asked Sep 03 '14 19:09

Caxton


People also ask

How do you solve OSError 193 %1 is not a valid Win32 application?

If you see the OSError: [WinError 193] %1 is not a valid Win32 application ; this happens because TensorFlow is a 64-bit application, while Python is 32-bit, and you are trying to run a 32-bit version of Python with a 64-bit TensorFlow. To fix this, you need to install the 32-bit version of TensorFlow.

What is 1 is not a valid Win32 application?

In most cases, the “1 is not a valid Win32 application” occurs due to the incompatibility between the Windows version/type and program. Please make sure you have downloaded the right version of the installer file. Press Windows key + R to call out the Run box.


2 Answers

The error is pretty clear. The file hello.py is not an executable file. You need to specify the executable:

subprocess.call(['python.exe', 'hello.py', 'htmlfilename.htm']) 

You'll need python.exe to be visible on the search path, or you could pass the full path to the executable file that is running the calling script:

import sys subprocess.call([sys.executable, 'hello.py', 'htmlfilename.htm']) 
like image 186
David Heffernan Avatar answered Oct 05 '22 10:10

David Heffernan


Python installers usually register .py files with the system. If you run the shell explicitly, it works:

import subprocess subprocess.call(['hello.py', 'htmlfilename.htm'], shell=True) # --- or ---- subprocess.call('hello.py htmlfilename.htm', shell=True) 

You can check your file associations on the command line with

C:\>assoc .py .py=Python.File  C:\>ftype Python.File Python.File="C:\Python27\python.exe" "%1" %* 
like image 24
tdelaney Avatar answered Oct 05 '22 10:10

tdelaney