95

I installed Python 3.1 and the Pygame module for Python 3.1. When I type import python in the console I get the following error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import pygame
  File "C:\Python31\lib\site-packages\pygame\__init__.py", line 95, in <module>
    from pygame.base import *
ImportError: DLL load failed: %1 is not a valid Win32 application.
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Parseltongue
  • 11,157
  • 30
  • 95
  • 160
  • 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). – CristiFati Dec 20 '22 at 22:35

5 Answers5

149

It could be due to the architecture of your OS. Is your OS 64 Bit and have you installed 64 bit version of Python? It may help to install both 32 bit version Python 3.1 and Pygame, which is available officially only in 32 bit and you won't face this problem.

I see that 64 bit pygame is maintained here, you might also want to try uninstalling Pygame only and install the 64 bit version on your existing python3.1, if not choose go for both 32-bit version.

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
  • 4
    This hits the nail on the head for wxpython too :) – Matt Lyons-Wood Oct 12 '11 at 09:46
  • also works for getting PIL module working in GAE dev_appserver on Windows 7 – HorseloverFat Jan 23 '13 at 16:16
  • I got a similar error when installing pygame for Python 3.2 on a system with Python 3.4 installed (both 32 bit). The pygame website didn't provide a newer version, but it was available [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame)! – andreasdr Nov 22 '14 at 18:12
  • @SenthilKumaran, If I have 64-bit Windows and Install 32-python and 32-libs, shoul I have this problem? I can't install `numpy+mkl` to use `sklearn` –  May 27 '16 at 11:25
  • Great man, I ran into this when I stupidly decided that using pycharm would be a great idea.Everything was perfect before installing it.After installing it.My django server won't. Thanks you.Its working again. – ALLSYED Jun 30 '16 at 01:17
9

Looks like the question has been long ago answered but the solution did not work for me. When I was getting that error, I was able to fix the problem by downloading PyWin32

Alexis
  • 23,545
  • 19
  • 104
  • 143
3

I had installed Python 32 bit version and psycopg2 64 bit version to get this problem. I installed psycopg2 32 bit version and then it worked.

Jon
  • 1,060
  • 8
  • 15
2

Had this issue on Python 2.7.9, solved by updating to Python 2.7.10 (unreleased when this question was asked and answered).

Adam Francey
  • 133
  • 6
1

Another possible cause of similar issue could be wrong processorArchitecture in the cx_freeze manifest, trying to load x86 common controls dll in x64 process - should be fixed by this patch:

https://bitbucket.org/anthony_tuininga/cx_freeze/pull-request/71/changed-x86-in-windows-manifest-to/diff

liborm
  • 2,634
  • 20
  • 32