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? Thanks in advance.
This question is related to
python
subprocess
python-3.4
For anyone experiencing this on windows after an update
What happened was that Windows Defender made some changes. Possibly cause running data extraction scripts, but python.exe got reduced to 0kb for that project. Copying the python.exe from another project and replacing it solved for now.
I got the same error while I forgot to use shell=True
in the subprocess.call
.
subprocess.call('python modify_depth_images.py', shell=True)
To run an external command without interacting with it, such as one would do with
os.system()
, Use thecall()
function.import subprocess Simple command subprocess.call(['ls', '-1'], shell=True)
Issue comes when any application you want to run needs python 32 bit variants and you have 64 bit variant
Note : Once you install python 32 bit variant,dont forget to install all required packages using pip of this new python 32 bit variant
The file hello.py is not an executable file. You need to specify a file like python.exe
try following:
import sys
subprocess.call([sys.executable, 'hello.py', 'htmlfilename.htm'])
OSError: [WinError 193] %1 is not a valid Win32 application
This error is most probably due to this line import subprocess
I had the same issue and had solved it by uninstalling and reinstalling python and anaconda then i used jupyter and wrote pip install numpy this gave me the whole path where it was getting my site-packages from i deleted my site-packages folder and then the error dissappeared. Actually because i had 2 folders for site-packages one with anaconda and other somewhere in app data(which had some issues in it), since i deleted that site-package folder then it automatically started taking my libraries from site-package folder which was with anaconda hence the problem was solved.
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" %*
Uninstalling numpy
from command line / terminal through pip
fixed the error for me:
pip uninstall numpy
I too faced same issue and following steps in resolution of this.
Regards Vj
C/program files/
and user/sukhendra/AppData
then only Anaconda is remaining in my PC so opened Anaconda and then it's all working fine for me
All above solution are logical and I think covers the root cause, but for me, none of the above worked. Hence putting it here as may be helpful for others.
My
environment
was messed up. As you can see from the traceback, there are two python environments involved here:
C:\Users\example\AppData\Roaming\Python\Python37
C:\Users\example\Anaconda3
I cleaned up the path and just deleted all the files from C:\Users\example\AppData\Roaming\Python\Python37
.
Then it worked like the charm.
I hope others may find this helpful.
This link helped me to found the solution.
Source: Stackoverflow.com