PYGame - ImportError:没有名为 locals Raspberry Pi 的模块

2024-04-27

我有以下代码:

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

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

 and so on

该应用程序看起来一切正常,但是当我编译代码时出现以下错误:

 Traceback (most recent call last):
 File "fish.py", line 4, in <module>
import pygame, random
 File "/home/pi/pygame/pygame.py", line 2, in <module>
ImportError: No module named locals


------------------
(program exited with code: 1)
Press return to continue

有人可以帮忙吗?我是 Python 和 Linux 新手。

我做了以下事情:

 pi@raspberrypi:~$ sudo apt-get install python-pygame
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 python-pygame is already the newest version.
 0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.
 pi@raspberrypi:~$ 

你的问题是你有一个名为pygame.py,或这样一个名为的文件留下的字节码pygame.pyc.


Calling import pygame有效,但它不会导入 pygame,而是导入那个文件。

由于您的文件找不到名为的模块locals在该文件中,会引发错误。

因此,只需将文件重命名为除pygame.py或您想要导入的其他模块,或者,如果有pygame.pyc字节码文件,删除它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PYGame - ImportError:没有名为 locals Raspberry Pi 的模块 的相关文章

随机推荐