Python 解决“DLL 加载失败:%1 不是有效的 Win32 应用程序。” 用于 Pygame

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4676433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 16:53:25  来源:igfitidea点击:

Solving "DLL load failed: %1 is not a valid Win32 application." for Pygame

pythonpygame

提问by Parseltongue

I recently 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:

我最近安装了 Python 3.1 和 Python 3.1 的 Pygame 模块当我在控制台中输入 import python 时,我收到以下错误:

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.

Please help!

请帮忙!

采纳答案by Senthil Kumaran

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.1and Pygame, which is available officially only in 32 bit and you won't face this problem.

这可能是由于您的操作系统的架构。您的操作系统是 64 位并且您是否安装了 64 位版本的 Python?安装 32 位版本的Python 3.1Pygame可能会有所帮助,后者仅在 32 位正式可用,您不会遇到此问题。

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.

我看到这里维护64 位 pygame ,您可能还想尝试仅卸载 Pygame 并在现有的 python3.1 上安装 64 位版本,如果没有选择同时使用 32 位版本。

回答by Alexis

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

看起来这个问题很久以前就得到了回答,但该解决方案对我不起作用。当我收到该错误时,我能够通过下载PyWin32来解决该问题

回答by liborm

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

类似问题的另一个可能原因可能是processorArchitecturecx_freeze 清单中的错误,尝试在 x64 进程中加载​​ x86 通用控件 dll - 应通过此补丁修复:

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

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

回答by Jon

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.

我已经安装了 Python 32 位版本和 psycopg2 64 位版本来解决这个问题。我安装了 psycopg2 32 位版本,然后它工作了。

回答by Adam Francey

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

在 Python 2.7.9 上有这个问题,通过更新到 Python 2.7.10 解决(在提出和回答这个问题时未发布)。