0

I am trying to run the same code on my new PC (Windows 11). I installed Python 2.7 and matplotlib in both 64 bit but I still get "ImportError: DLL load failed: %1 is not a valid Win32 application."

I know this has been asked many times (e.g., here, here, here, here, here, here) and after reading all of these previously-asked posts, it seems you get this error when Python and the module bit do not match (e.g., Python in 32 bit and module in 64 bit, and vice versa). That is why I made sure that both are running in 64 bit. I restarted my PC, and I even installed pywin32 in 64 bit but that did not fix this issue.

My environment and versions Windows 11 Pro 64 bit Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. matplotlib: 2.2.5 pywin32: 228

Codes when the error occurs in PowerShell import csv, os, os.path, pdb import matplotlib.pyplot as plt

I also get the same error when I try to import _tkinter (based on another question)

I have been trying to figure this out for days now and I would appreciate it if anybody could suggest what else I could do to make it work. Thanks!

owl
  • 1,841
  • 6
  • 20
  • 30
  • 1
    More details: [\[SO\]: Python Ctypes - loading dll throws OSError: \[WinError 193\] %1 is not a valid Win32 application (@CristiFati's answer)](https://stackoverflow.com/a/57297745/4788546). Where did you install *Python 2.7* from? What about other packages? – CristiFati Dec 20 '22 at 22:39
  • Thank you for the details and your help! I installed Python from python-2.7.16.amd64.msi file, matplotlib from matplotlib-2.2.5-cp27-cp27m-win_amd64.whl file, numpy from numpy-1.16.6+mkl-cp27-cp27m-win_amd64.whl, scipy from scipy-0.16.1-win32-superpack-python2.7.exe file, and others using pip like install --ignore-installed pywin32 --upgrade. I did get an error when I tried to install matplotlib and pywin32 initially saying that I had another version. I tried uninstalling but it gave me an error so I did pip install --ignore-installed matplotlib-2.2.5-cp27-cp27m-win_amd64.whl. – owl Dec 21 '22 at 00:06
  • 1
    Most likely you messed up the *Python* installation (now or sometime in the past). I installed (clean) the same *.msi*, then `python -m pip install matplotlib==2.2.5 pywin32==228` and everything is fine. You should post the entire traceback. – CristiFati Dec 21 '22 at 07:33
  • Thank you so much! I followed exactly what you suggested, and it did finally take care of the problem! I literally spent days trying to fix this and I really appreciate your help! – owl Dec 21 '22 at 15:41

0 Answers0