Pygame 安装,没有名为 pygame.base 的模块 [英] Pygame installation, no module named pygame.base

查看:237
本文介绍了Pygame 安装,没有名为 pygame.base 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to install pygame with the powershell from VS 2019 with python 3.8, I use python3 -m pip install -U pygame --user and it installs pygmae just fine but when I try to run python3 -m pygame.examples.aliens it says no module named pygame.base. I have python 3.6.5 and 3.7 as well in case that has an effect.

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'

推荐答案

jm96:

  1. 检查 pygame 是否在 pip3 列表中:

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

它没有,安装它:

$ -> python3 -m pip install pygame

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

Note: Keep in mind the following (you have used the user parameter):

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

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 * 但如果您不需要所有模块,则不需要.
  1. Check the imported module. You use from pygame.base import *. Change it to from pygame import base. You can do from pygame import * but if you don't need all modules is no necessary.

$ -> 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

这篇关于Pygame 安装,没有名为 pygame.base 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆