[英]Can't import pygame - ModuleNotFoundError: No module named 'pygame.base'
I am having the same (or very similar) issue, as here ( Importing Pygame, ModuleNotFoundError: No module named 'pygame.base' ) but the recommendations didn't help me.我遇到了相同(或非常相似)的问题,就像这里( 导入 Pygame, ModuleNotFoundError: No module named 'pygame.base' ),但这些建议对我没有帮助。
I had to wipe my Windows machine 2 days ago, so I reinstalled Python 3.9 (from python.org), and installed pygame without any problems. 2 天前我不得不擦拭我的 Windows 机器,所以我重新安装了 Python 3.9(来自 python.org),并且安装了 pygame 没有任何问题。
When I try to import pygame at the beginning of a file, my error looks like this:当我尝试在文件开头导入 pygame 时,我的错误如下所示:
Traceback (most recent call last):
File "c:\g\code\snakegame\py\snakegame.py", line 1, in <module>
import pygame
File "C:\Program Files\Python39\lib\site-packages\pygame\__init__.py", line 90, in <module>
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ModuleNotFoundError: No module named 'pygame.base'
If I try running the following, as recommended on ( Pygame installation, no module named pygame.base )如果我尝试运行以下内容,请按照( Pygame 安装,没有名为 pygame.base 的模块)上的建议
from pygame import base
import sys
module = 'pygame.base'
if module in sys.modules:
print("OK")
else:
print("KO")
I get...我得到...
Traceback (most recent call last):
File "c:\g\code\snakegame\py\pygame_import.py", line 1, in <module>
from pygame import base
File "C:\Program Files\Python39\lib\site-packages\pygame\__init__.py", line 90, in <module>
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ModuleNotFoundError: No module named 'pygame.base'
I tried uninstalling and reinstalling pygame.我尝试卸载并重新安装pygame。
python -m pip uninstall pygame
python -m pip install -U pygame
I tried reinstalling python.我尝试重新安装python。 I tried python from python.org, the python app from the windows store, and I also tried installing pycharm via the jetbrains toolbox.
我尝试了来自 python.org 的 python,来自 Windows 商店的 python 应用程序,我还尝试通过 jetbrains 工具箱安装 pycharm。
I tried uninstalling pygame and installing pygame-2.0.0-cp39-cp39-win32.whl manually.我尝试卸载 pygame 并手动安装 pygame-2.0.0-cp39-cp39-win32.whl。 The .whl was pulled from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
.whl 来自https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
I checked and there does exist this .pyd... C:\\Program Files\\Python39\\Lib\\site-packages\\pygame\\base.cp39-win32.pyd我查了一下,确实存在这个 .pyd ... C:\\Program Files\\Python39\\Lib\\site-packages\\pygame\\base.cp39-win32.pyd
I checked for related issues on https://github.com/pygame/pygame/issues我在https://github.com/pygame/pygame/issues上检查了相关问题
Anyone have any ideas?谁有想法?
Pygame isn't compatible with Python 3.9 ON WINDOWS at the moment. Pygame 目前在 WINDOWS 上与 Python 3.9 不兼容。 In fact a lot of packages aren't.
事实上,很多包都不是。 Pygame is compatible with Python 3.7 on windows, so you are gonna have to install python 3.7.7 or earlier.
Pygame 与 Windows 上的 Python 3.7 兼容,因此您必须安装 Python 3.7.7 或更早版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.