Windowserror: [Error 193] %1 Is Not a Valid Win32 Application in Python

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

I resolved problem.

  1. I uninstalled Anaconda
  2. I deleted Python folder in : C:\Users\Admin\AppData\Roaming
  3. I removed .conda folder in C:\Users\Admin
  4. I installed Anaconda
  5. I insert into C:\Windows\System32, pythoncom38.dll and
    pywintypes38.dll from C:\ProgramData\Anaconda3\Lib\site-packages\
  6. I uninstalled wordcloud and Numpy, then installed

pip uninstall wordcloud
pip uninstall Numpy
pip install wordcloud

pip install Numpy

OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows

This error message...

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

...implies that the underlying OS doesn't recognizes %1 i.e. the system variable PATH as a valid Win32 application i.e. a executable binary.


To initiate a Selenium driven GeckoDriver controlled Firefox session you need to:

  • Download the latest version of GeckoDriver binary version, place it in your system.

  • Next in your code block you need to mention the absolute path of the binary through the Key executable_path as follows:

    from selenium import webdriver

    self.myday_driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')

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

The problem is this line:

pytesseract.pytesseract.tesseract_cmd = 'Lib/site-packages/pytesseract/pytesseract.py'

You need to set pytesseract.pytesseract.tesseract_cmd to the location of the Tesseract executable. You have instead set it to some Python script.

See this question for some examples of what this should be set to.

OSError: [WinError 193] %1 is not a valid Win32 application while reading custom DLL in python with CTypes

This is a typical CPU architecture (032bit (your .dll) vs. 064bit (Python process that tries to load it)) mismatch. Check [SO]: Python Ctypes - loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application (@CristiFati's answer) for more details.

Build the 064bit (pc064) version of your your .dll.
You can use the command line tools from the aforementioned URL, or you can set the VStudio IDE to do it, as explained in [MS.Docs]: How to: Configure Visual Studio C++ projects to Target 64-Bit, x64 Platforms:

  1. Open the C++ project that you want to configure.
  2. Open the property pages for that project. For more information, see Set C++ compiler and build properties in Visual Studio.
  3. Choose the Configuration Manager button to open the Configuration Manager dialog box.
  4. In the Active Solution Platform drop-down list, select the <New...> option to open the New Solution Platform dialog box.
  5. In the Type or select the new platform drop-down list, select a 64-bit target platform.
  6. Choose the OK button. The platform that you selected in the preceding step appears under Active Solution Platform in the Configuration Manager dialog box.
  7. Choose the Close button in the Configuration Manager dialog box, and then choose the OK button in the <Projectname> Property Pages dialog box.

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

c:\windows\syswow64 contains 32-bit DLLs. Your Python path is c:\Program Files which is the 64-bit Python installation location. You can't mix.

Don't hard-code the path. Just use mydll = WinDLL('kernel32') and Windows will search the correct standard location for the Python running (32- or 64-bit).

OSError: [WinError 193] %1 is not a valid Win32 application - when trying to import numpy

Okay, so this eventually helped me:

  1. I uninstalled only a numpy module with "pip uninstall numpy",

  2. I reinstalled it once again with "pip install numpy",

  3. I ran python, imported just one function from numpy (as I thought that maybe just some of the functions can't be imported, not entire
    numpy) - "from numpy import array"

  4. The function worked,so I tried to import the entire numpy once again and this time it succeeded without OSError.



Related Topics



Leave a reply



Submit