Cant find Pygame Module

后端 未结 1 332
感情败类
感情败类 2021-01-28 09:03

I just started game developing in python with pygame and I have the following code:

bif=\"main_background.jpg\"
mif=\"player_head.png\"

import pygame, sys
from          


        
相关标签:
1条回答
  • 2021-01-28 09:26

    I'm about 83.4% sure that you named your script pygame.py (or possibly created another file with the same name in the same directory as your script).

    If you do that, Python has no way of knowing what you want to load when you import pygame. It could be your script, it could be the installed package—they both have the same name.

    What ends up happening is that import pygame imports your script, then from pygame.locals import * looks for a module called locals inside your script. Since your script is a script, and not a package, Python just gets confused and prints a confusing ImportError.

    Python 3.x gives you some ways around this, but 2.x does not, and I'm guessing you're using 2.x.

    So, the solution is:

    • Rename your script to mygame.py.
    • Delete any other files in the same directory as your script named pygame.py.
    0 讨论(0)
提交回复
热议问题