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:
$ -> pip3 list --format=columns | grep -i pygame
pygame 1.9.6
It it doesn't, install it:
$ -> 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.
What is the purpose of "pip install --user..."?
$ -> pip3 list --format=columns --user | grep -i pygame
pygame 1.9.6
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
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.