简体   繁体   English

python pygame 使用 spyder

[英]python pygame using spyder

When I code this pygame import, it doesn't work with spyder:当我对此 pygame 导入进行编码时,它不适用于 spyder:

import pygame

Window_width=700
Window_hight=500

pygame.init()
size= (Window_width, Window_hight)
screen= pygame.display.set_mode(size)
pygame.display.set_caption("Game")

pygame.quit()

The answer of spyder is : spyder 的回答是:

>Python 2.7.14 |Anaconda, Inc.| (default, Nov  8 2017, 13:40:45) [MSC v.1500 
64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

 >File "C:/Users/hpinko/Desktop/python scripts/game.py", line 1, in <module>
   import pygame

ImportError: No module named pygame

Please, help me to fix this.请帮我解决这个问题。

It might be because pygame module is not installed on your pc.这可能是因为你的电脑上没有安装 pygame 模块。 You can install it by using pip.您可以使用 pip 安装它。

Step 1 : Go to the directory in which python is installed on command prompt by using cd c:\\Python27\\ .步骤 1 :使用cd c:\\Python27\\转到命令提示符下安装 python 的目录。 Step 2 : Go to scripts folder by entering the command cd Scripts .第 2 步:通过输入命令cd Scripts进入脚本文件夹。 You might want to add this folder to your path variable to avoid navigating to c:\\python27\\Scripts folder every time you want to install a package Step 3 : Install pygame by running pip install pygame您可能希望将此文件夹添加到路径变量中,以避免每次要安装软件包时都导航到c:\\python27\\Scripts文件夹第 3 步:通过运行pip install pygame

I had the same issue but I followed Tom's advice and used CMD to navigate to the Scripts folder.我遇到了同样的问题,但我遵循了 Tom 的建议并使用 CMD 导航到 Scripts 文件夹。 Then I went to https://www.pygame.org/wiki/GettingStarted and used py -m pip install -U pygame --user for windows installation.然后我去了https://www.pygame.org/wiki/GettingStarted并使用 py -m pip install -U pygame --user 进行 Windows 安装。

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

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