ModuleNotFoundError:安装时没有名为“pgzrun"的模块? [英] ModuleNotFoundError: No module named 'pgzrun' when I have it installed?
问题描述
IDLE为什么这么说
ModuleNotFoundError: 没有名为pygame"的模块
我什么时候安装的?我用pip安装了它.我尝试删除导入,但 IDLE 给我一个名称错误,说 pygame 未定义..我试着做
when I have it installed? I installed it with pip. I tried deleting the import but then IDLE gives me a name error saying pygame isn't defined.. I tried doing
import pygame
和
import pgzrun
和
import pgzero
这是我使用的代码:
import pygame
screen = pygame.display.set_mode((800, 600))
我还使用了一个名为 mu 的代码编辑器,但是如果我使用函数,它会给我一个名称错误.
I also used a code editor called mu but then if I use functions, it gives me a name error.
推荐答案
Go to python/scripts
路径并尝试使用 python -m pip uninstall pygame
然后卸载它使用 python -m pip install pygame --user
Got to python/scripts
path and try to uninstall it with python -m pip uninstall pygame
then install it with python -m pip install pygame --user
安装python包时没有--user
,pip默认安装在/usr/local/lib/python3等系统目录下
,这需要 root 访问权限.而在使用 --user
时,pip 会在您的主目录中安装软件包,这不需要任何 root 访问权限或特殊权限.所以这给我们留下了两种正确安装 Pygame 的方法,第一种是使用 --user
在没有特殊权限的情况下安装它,第二种选择是在 Windows 上以管理员身份运行终端或作为Linux 上的 root 用户授予它 root 访问权限以成功下载 Pygame.
When installing a python package without --user
, pip defaults to installing it on the system directory such as /usr/local/lib/python3
, and this requires root access. While when using --user
, pip installs the package in your home directory which doesn't require any root access or special privileges. So that leaves us with two ways to install Pygame correctly, The first one is to use --user
to install it without special privileges and the Second choice is to run the terminal as an administrator on Windows or as root on Linux to give it root access for it to download Pygame successfully.
这篇关于ModuleNotFoundError:安装时没有名为“pgzrun"的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!