OSError: [WinError 193] %1 is not a valid Win32 application
Question:
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:Python34libsubprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:Python34libsubprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:Python34libsubprocess.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?
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'])
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:Python27python.exe" "%1" %*
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 the call()
function.
import subprocess
Simple command subprocess.call(['ls', '-1'], shell=True)
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.
Uninstalling numpy
from command line / terminal through pip
fixed the error for me:
pip uninstall numpy
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:UsersexampleAppDataRoamingPythonPython37
C:UsersexampleAnaconda3
I cleaned up the path and just deleted all the files from C:UsersexampleAppDataRoamingPythonPython37
.
Then it worked like the charm.
This link helped me to found the solution.
For me issue got resolved after following steps :
- Installing python 32 bit version on windows.
- Add newly installed python and it’s script folder(where pip resides in environment variable)
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
I solved this by Following steps:
- 1 > Uninstalled python
- 2 > removed Python37 Folder from C/program files/ and user/sukhendra/AppData
- 3 > removed all python37 paths
then only Anaconda is remaining in my PC
so opened Anaconda and then it’s all working fine for me
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 too faced same issue and following steps in resolution of this.
- I removed unnecessary python path from system except anaconda path.
- C:Users<user-Name>AppDataRoaming<python> = remove any unnecessary python files /folder. these files may interfere with current execution.
Regards
Vj
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'])
My problem was involving poetry
and argparse
.
I was calling the script with arguments like so:
poetry run .srcscript.py --help
and was getting this same errorr, so when I changed my command to:
poetry run python.exe .srcscript.py --help
then and all worked fine.
I got this error while trying to install SpaCy. I had Python 3.7 32-bit version, which didn’t let me install SpaCy.
First, I tried to upgrade to Python 3.9 64-bit version and uninstalled python 3.7. Then to save my libraries I copied the site-packages of the python 3.7 version to the 3.9 version, which gave me this error while downloading SpaCy.
While there were a lot of errors in the lib folder, but I solved [OSError: WinError 193] by uninstalling NumPy and then re-installing it.
Delete all the python folders from
C:/program files/user/AppData/python
then it will work (if you have jupyter error).
This error occurred to me while running a chrome driver code using selenium in Python language , the error was fixed when I deleted my current chrome driver and installed the latest one compatible with my PC , you can have a detailed summary on this youtube video
https://www.youtube.com/watch?v=WnWQgUerR0c
Welcome.
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:Python34libsubprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:Python34libsubprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:Python34libsubprocess.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?
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'])
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:Python27python.exe" "%1" %*
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 withos.system()
, Use thecall()
function.import subprocess Simple command subprocess.call(['ls', '-1'], shell=True)
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.
Uninstalling numpy
from command line / terminal through pip
fixed the error for me:
pip uninstall numpy
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:UsersexampleAppDataRoamingPythonPython37
C:UsersexampleAnaconda3
I cleaned up the path and just deleted all the files from C:UsersexampleAppDataRoamingPythonPython37
.
Then it worked like the charm.
This link helped me to found the solution.
For me issue got resolved after following steps :
- Installing python 32 bit version on windows.
- Add newly installed python and it’s script folder(where pip resides in environment variable)
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
I solved this by Following steps:
- 1 > Uninstalled python
- 2 > removed Python37 Folder from C/program files/ and user/sukhendra/AppData
- 3 > removed all python37 paths
then only Anaconda is remaining in my PC
so opened Anaconda and then it’s all working fine for me
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 too faced same issue and following steps in resolution of this.
- I removed unnecessary python path from system except anaconda path.
- C:Users<user-Name>AppDataRoaming<python> = remove any unnecessary python files /folder. these files may interfere with current execution.
Regards
Vj
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'])
My problem was involving poetry
and argparse
.
I was calling the script with arguments like so:
poetry run .srcscript.py --help
and was getting this same errorr, so when I changed my command to:
poetry run python.exe .srcscript.py --help
then and all worked fine.
I got this error while trying to install SpaCy. I had Python 3.7 32-bit version, which didn’t let me install SpaCy.
First, I tried to upgrade to Python 3.9 64-bit version and uninstalled python 3.7. Then to save my libraries I copied the site-packages of the python 3.7 version to the 3.9 version, which gave me this error while downloading SpaCy.
While there were a lot of errors in the lib folder, but I solved [OSError: WinError 193] by uninstalling NumPy and then re-installing it.
Delete all the python folders from
C:/program files/user/AppData/python
then it will work (if you have jupyter error).
This error occurred to me while running a chrome driver code using selenium in Python language , the error was fixed when I deleted my current chrome driver and installed the latest one compatible with my PC , you can have a detailed summary on this youtube video
https://www.youtube.com/watch?v=WnWQgUerR0c
Welcome.