PYGame - ImportError: No module named locals Raspberry Pi

前端 未结 2 1126
说谎
说谎 2021-01-07 12:52

I have the following code:

 #!/usr/bin/python
 # -*- coding: iso-8859-15 -*-

 import pygame, random
 from pygame.locals import *
 pygame.init()
 clock = pyg         


        
相关标签:
2条回答
  • 2021-01-07 13:09

    Your problem is that you have a file that is named pygame.py, or a bytecode left-over from such a file named pygame.pyc.


    Calling import pygame works, but it will not import pygame, but the that very file.

    And since your file can't find a module named locals in that file, the error is raised.

    So, just rename your file to anything other than pygame.py or other modules you want to import, or, if there's a pygame.pyc bytecode file, remove that.

    0 讨论(0)
  • 2021-01-07 13:27

    Try using IDLE instead of IDLE 3. It worked for me and I had exactly the same problem shown above.

    0 讨论(0)
提交回复
热议问题