简体   繁体   中英

Pygame won't import to python

When i type import pygame, i get an error that reads:

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. Here is how I get out of the shell:

  1. Save the Idle Shell as a .py in a location of your choice
  2. Afterward, find the .py you created.
  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. 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.

This question at Game Developement (another Stack Exchange Site) should answer your question: Installing the right version of PyGame
This user can't make Python to know that PyGame is there so he asks that question. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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