[英]ImportError: no module named pygame?
I can import pygame through the command line, and through all my other prorams, but it brings up an error in my crosshairs program: 我可以通过命令行以及所有其他程序导入pygame,但这会在我的十字准线程序中引发错误:
Traceback (most recent call last): File "C:\\Users\\Family\\Desktop\\pys\\Crosshairs(2).py", line 1, in import pygame ImportError: No module named 'pygame' 追溯(最近一次通话最近):导入pygame中第1行的文件“ C:\\ Users \\ Family \\ Desktop \\ pys \\ Crosshairs(2).py”导入错误:没有名为“ pygame”的模块
I have no idea what the heck it's talking about, but I'm thinking this could be windows vista being a crap hole(vista is verry glitchy) but I'm not too sure. 我不知道它到底在说什么,但是我想这可能是Windows Vista成为一个废话(vista有点毛刺),但我不太确定。 Does anyone know what the problem is?
有人知道问题出在哪里吗? If you need it, here is the code:
如果需要,请使用以下代码:
import pygame
import math
import sys
WHITE = (255, 255, 255)
BLACK = ( 0, 0, 0)
RED = (255, 0, 0)
BGCOLOR = WHITE
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
class Control(object):
def __init__(self):
self.bullet_holes = []
self.screen = pg.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
self.done = False
self.clock = pg.time.Clock()
def update(self):
vis = False
pygame.mouse.get_visible(vis)
self.mousex,self.mousey = pg.mouse.get_pos()
self.screen.fill(BGCOLOR)
pygame.draw.circle(self.screen, RED, (320,240),50,10)
pygame.draw.circle(self.screen, WHITE, (320,240),40,10)
pygame.draw.circle(self.screen, RED, (320,240),30,10)
pygame.draw.circle(self.screen, WHITE, (320,240),20,10)
pygame.draw.circle(self.screen, RED, (320,240),10,10)
pygame.draw.line(self.screen, BLACK, (self.mousex - 2000, self.mousey),
(self.mousex + 2000, self.mousey))
pygame.draw.line(self.screen, BLACK, (self.mousex, self.mousey - 2000),
(self.mousex, self.mousey + 2000))
for bullet_pos in self.bullet_holes:
pygame.draw.circle(self.screen,BLACK,bullet_pos,5)
def event_loop(self):
for event in pg.event.get():
if event.type == pg.QUIT or (event.type == pg.KEYUP and
event.key==pg.K_ESCAPE):
self.done = True
elif event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
self.bullet_holes.append(event.pos)
pygame.image.save(self.screen,'Highscores.png')
def main_loop(self):
while not self.done:
self.update()
self.event_loop()
pygame.display.flip()
self.clock.tick(60)
if __name__ == '__main__':
game = Control()
game.main_loop()
pygame.quit()
sys.exit()
Your pygame module is not in the path and cannot be found. 您的pygame模块不在路径中,无法找到。 Correct this by moving it or using PySys_SetPath().
通过移动它或使用PySys_SetPath()纠正此问题。
You could do it with sys.path.insert
command: 您可以使用
sys.path.insert
命令执行此操作:
import sys
path_to_folder = os.path.abspath("c:\\Your\\destination\\folder")
sys.path.insert(0, path_to_folder)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.