简体   繁体   English

Pygame 不会导入到 python

[英]Pygame won't import to python

When i type import pygame, i get an error that reads:当我输入 import pygame 时,我收到一个错误消息:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
  File "C:\Python27\lib\site-packages\pygame\__init__.py", line 95, in <module>
    from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
>>> 

Does anybody know what this means?有人知道这是什么意思吗?

这意味着您需要查看 Dependency Walker 中的pygame\\base.pyd并查看它找不到哪个 DLL。

I made this mistake too.我也犯过这个错误。 The problem is that you are using the Idle Shell to attempt to build a Python program.问题是您正在使用空闲 Shell 尝试构建 Python 程序。 Here is how I get out of the shell:这是我如何摆脱外壳:

  1. Save the Idle Shell as a .py in a location of your choice在您选择的位置将空闲 Shell 保存为 .py
  2. Afterward, find the .py you created.之后,找到您创建的 .py。
  3. Left click, then Right click to display the context submenu (the menu with copy/paste)左键单击,然后右键单击以显示上下文子菜单(带有复制/粘贴的菜单)
  4. Select "Edit with Idle"选择“在空闲时编辑”
  5. This will open the .py file in the Editor Window.这将在编辑器窗口中打开 .py 文件。 Delete all extra content to create a blank screen删除所有额外内容以创建一个空白屏幕
  6. Now you can import your modules and begin programming:现在您可以导入模块并开始编程:

     import os, sys import pygame from pygame.locals import * [...]

This will give you the head start to work with pygame.这将为您提供使用 pygame 的良好开端。

This question at Game Developement (another Stack Exchange Site) should answer your question: Installing the right version of PyGame Game Developement(另一个 Stack Exchange 站点)上的这个问题应该可以回答您的问题: 安装正确版本的 PyGame
This user can't make Python to know that PyGame is there so he asks that question.该用户无法让 Python 知道 PyGame 存在,因此他提出了这个问题。 His question should be similar to yours, making it convinient for you.他的问题应该与你的相似,这样你就可以很方便地提出来。 I hope this helps you!我希望这可以帮助你!

在命令提示符下,如果您使用的是 Windows PC,请编写pip install pygame如果您使用的是 Linux 或 MacOS,请编写pip3 install pygame

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM