如何解决如何修复外星人入侵文件中pygame的ImportError“Library not loaded”?
这是我的代码:
import sys
import pygame
class AlienInvasion:
"""Overall class to manage game assets and behavior"""
def __init__(self):
"""Initialize the game,and create game resources."""
pygame.init()
self.screen = pygame.display.set_mode((1200,800))
pygame.display.set_caption("Alien Invasion")
def run_game(self):
"""Start the main loop for the game"""
while True:
# Watch for keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Make the most recently drawn screen visible
pygame.display.flip()
if __name__ == '__main__':
# Make a game instance and run the game
ai = AlienInvasion()
ai.run_game()
我已经通过 Mac 上的终端安装了 pygame。
当我尝试运行我的代码时,它给了我以下错误。
我期待一个空白的屏幕。
我尝试了 pip uninstall pygame
和 pip install pygame
,但是没有用。
如果有人可以提供帮助那就太好了。
Traceback (most recent call last):
File "/Users/mycomputer/Desktop/python_work/alien_invasion.py",line 3,in <module>
import pygame
File "/Users/mycomputer/Library/Python/3.9/lib/python/site-packages/pygame/__init__.py",line 81,in <module>
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ImportError: dlopen(/Users/mycomputer/Library/Python/3.9/lib/python/site-packages/pygame/base.cpython-39-darwin.so,2): Library not loaded: /System/Library/Frameworks/Metal.framework/Versions/A/Metal
Referenced from: /Users/mycomputer/Library/Python/3.9/lib/python/site-packages/pygame/base.cpython-39-darwin.so
Reason: image not found
解决方法
您确实使用 pip
和 brew
卸载 pygame 并使用 brew
安装 pygame
pip uninstall pygame
brew uninstall pygame
brew install pygame
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。