0

I'm using a 64-bit version of python, on a 64-bit version of Windows 10, to run some code. However, the code fails on importing ctypes. In fact, the minimum example for the problem is simply:

import ctypes

Which fails here:

from _ctypes import Union, Structure, Array

With this error:

DLL load failed: %1 is not a valid Win32 application

Reading around, this seems to be an issue with loading a 32-bit dll into a 64-bit version of python (or vice-versa, but my version of python is 64-bit, so...). However, what I don't understand is that ctypes seems to be something that is bundled with python, i.e. it was installed when I installed python. Is ctypes itself in the wrong architecture? How is that possible if it came with the 64-bit version of Python?

Mike Cook
  • 15
  • 3
  • Depending on you python path, you might be loading wrong module. – ead Nov 16 '20 at 16:10
  • 1
    You got the architecture mismatch right: [\[SO\]: Python Ctypes - loading dll throws OSError: \[WinError 193\] %1 is not a valid Win32 application (@CristiFati's answer)](https://stackoverflow.com/questions/57187566/python-ctypes-loading-dll-throws-oserror-winerror-193-1-is-not-a-valid-win/57297745#57297745). However the cause seems to be funny. *CTypes* is part of standard *Python* library, and I doubt you got it like this from official sources. You might have a *\_ctypes.pyd* in your *PYTHONPATH* that gets loaded before the official one? – CristiFati Nov 17 '20 at 09:14

0 Answers0