简体   繁体   中英

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.

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.

When I try to import pygame at the beginning of a file, my error looks like this:

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 )

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.

python -m pip uninstall pygame
python -m pip install -U pygame

I tried reinstalling python. I tried python from python.org, the python app from the windows store, and I also tried installing pycharm via the jetbrains toolbox.

I tried uninstalling pygame and installing pygame-2.0.0-cp39-cp39-win32.whl manually. The .whl was pulled from 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

I checked for related issues on https://github.com/pygame/pygame/issues

Anyone have any ideas?

Pygame isn't compatible with Python 3.9 ON WINDOWS at the moment. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM