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

OSError: [WinError 193] %1 is not a valid Win32 application is a windows error wrapped as a Python error.

This post is a guide showing you why you are having this error and how you can get rid of it in the most efficient way possible, I will also include some alternative solutions that may help you.

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

First of all we need to understand why the error happens at all, the error seems like a Python related error but that is not the case, the error is related to both windows and python.

The error happens usually because of two reasons.

First reason is because you made a mistake by installing a 32 bit version of Python on a 64 bit windows machine. Or, you installed a 64 bit version of Python on a 32 bit version of windows.

Second reason is confusion of architecture, you are running Python 32 bit and loading a .dll which is a 64 bit .dll, or the opposite, you are running Python 64 bit and loading a .dll which is a 32 bit.

Solution 1 : remove Python 32 bit and install Python 64 bit on a windows 64 bit machine.

The solution for the first reason is simple, remove Python 32 bit and install Python 64 bit on a windows 64 bit machine. You can do the opposite if you are on a windows 32 bit machine by installing Python 32 bit.

Now let us talk about the second and most popular case.

Solution 2 : force the gcc compiler to compile 64 bit files.

Most of the time, this happens without you noticing, your gcc compiler is producing 32 bit compiled files, so you have to force it to compile 64 bit files.

To know if your file is 32 bit or 64 bit compiled right click on the file and click on properties, go to compatibility.

Check compatibility mode.

If you see windows xp in the list then your compiler is producing 32 bit files.

Change it to windows 64 bit.

Click close.

I hope this guide solved your probel, thank you for reading.

Summing-up

I hope this article helped you solve the error, If not, I hope the solutions presented here guided you at least in the right direction. Keep coding and cheers, see you in another post.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/