Pygame安装,没有名为pygame.base的模块

时间:2020-06-11 17:32:39

标签: python python-3.x visual-studio pygame

我正在尝试使用VS 2019和python 3.8从VS 2019安装带有Powershell的pygame,我使用python3 -m pip install -U pygame --user它将安装pygmae很好,但是当我尝试运行python3 -m pygame.examples .aliens,它说没有名为pygame.base的模块。我也有python 3.6.5和3.7,以防万一。

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "C:\Users\jos96\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pygame\__init__.py", line 130, in <module>
    from pygame.base import *
ModuleNotFoundError: No module named 'pygame.base'

1 个答案:

答案 0 :(得分:0)

jm96:

  1. 检查pygame是否在pip3列表中:
$ -> pip3 list --format=columns | grep -i pygame
pygame                       1.9.6       

没有,请安装:

$ -> python3 -m pip install pygame

注意:请记住以下几点(您已经使用了user参数):

$ -> man -P cat pip3 | grep -i '\--user'
       --user Install using the user scheme.

What is the purpose of "pip install --user ..."?

$ ->  pip3 list --format=columns --user | grep -i pygame
pygame            1.9.6     

  1. 检查导入的模块。您使用from pygame.base import *。将其更改为from pygame import base。您可以执行from pygame import *,但如果不需要所有模块,则没有必要。
$ -> cat pygame_import.py 
from pygame import base 
import sys

module = 'pygame.base'

if module in sys.modules:
    print("OK")
else:
    print("KO")

$ -> python3 pygame_import.py 
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
OK