[英]ImportError: No module named pygame, how do you fix this on a mac?
I am trying to create a game in python, just a beginner, and I installed pygame using the pip command pip install pygame
and it says "requirement already satisfied".我正在尝试在 python 中创建一个游戏,只是一个初学者,我使用 pip 命令pip install pygame
了 pygame,它说“要求已经满足”。 So, assuming it is installed, I hop onto VS Code, and the import pygame
to check if it is working, and the ImportError: No module named pygame
error popped up in the terminal, keep in mind I am on a MacBook.因此,假设它已安装,我跳到 VS Code,并import pygame
以检查它是否正常工作,并且在终端中弹出ImportError: No module named pygame
错误,请记住我在 MacBook 上。 Please help.请帮忙。 Here is the image of what the error is这是错误的图像
Remember to use pip3
on MacOS, pip
is for Python 2.请记住在 MacOS 上使用pip3
, pip
用于 Python 2。
Try this:尝试这个:
pip3 install pygame
and then run the command:然后运行命令:
python3 -c "import pygame"
If the second works, but in VSCode it doesn't, remember to use Python 3, instead of 2 for VSCode.如果第二个有效,但在 VSCode 中无效,请记住使用 Python 3,而不是 VSCode 的 2。
You shoud try pip3
instead pip
because I remembered that osx already have a version of python2.7(which deprecated).你应该尝试pip3
而不是pip
因为我记得 osx 已经有一个版本的 python2.7(已弃用)。 And remember to call CLI并且记得调用 CLI
python3 game.py
But I prefer using virtual environment ( venv )than install every packages in your user profile.但我更喜欢使用虚拟环境( venv )而不是在你的用户配置文件中安装每个包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.