简体   繁体   English

pip 安装 Pygame 后无法导入 Pygame

[英]Unable to import Pygame after pip install Pygame

I was trying to make a simple snake game in Python so I installed Pygame using pip install Pygame.我试图在 Python 中制作一个简单的蛇游戏,所以我使用 pip 安装 Pygame 安装 ZC1687207793A103。 After I installed it successfully, I tried importing Pygame but I got this error:安装成功后,我尝试导入 Pygame 但出现此错误:

ModuleNotFoundError: No module named 'pygame' ModuleNotFoundError:没有名为“pygame”的模块

I'm new to python so I'm really stuck.我是 python 的新手,所以我真的被卡住了。 I imported the module by the code.我通过代码导入了模块。

import pygame

if you are on windows:如果您在 windows:

open cmd and then type:打开 cmd 然后输入:

    cd\

    cd /d C:\Windows

    cd /d C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

and then type the command:然后输入命令:

    pip install pygame

if you are on Mac: just try python -m pip install pygame如果你在 Mac 上:试试python -m pip install pygame

if you are on linux:如果您使用的是 linux:

    pip install pygame 

Make sure you install pygame to the 'venv' folder of your project if you're using pycharm or sublime.如果您使用 pycharm 或 sublime,请确保将 pygame 安装到项目的“venv”文件夹中。 If you are using IDLE then open command prompt by holding: windows+R then searching cmd, or if you are on mac: cmd+space and search terminal.如果您使用的是 IDLE,请按住 windows+R 打开命令提示符,然后搜索 cmd,或者如果您在 mac 上:cmd+space 并搜索终端。 then type pip install pygame for windows, and python -m install pygame for mac. then type pip install pygame for windows, and python -m install pygame for mac.

If you are using Pycharm and your stuck goto settings and then proceed to python interpreter you will see a page listing installed modules in your Pycharm project click the small plus sign and search for pygame after that click Install Package. If you are using Pycharm and your stuck goto settings and then proceed to python interpreter you will see a page listing installed modules in your Pycharm project click the small plus sign and search for pygame after that click Install Package. If you still see an error message then repeat the steps, if that doesn't work try with internet connection.如果您仍然看到错误消息,请重复这些步骤,如果这不起作用,请尝试使用 Internet 连接。 I'm not good with Command Prompt but there's a way with it.我不擅长命令提示符,但有办法。 NOTE: I'm still a newbie in this area so I don't know if you'll consider my ideas useful Thank you注意:我还是这个领域的新手,所以我不知道你是否会认为我的想法有用谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM