所以我一直在尋找如何在Windows上運行python腳本,但我無法在虛擬機上使用Windows xp 64位運行pygame腳本。我試着用不同版本的python,pyinstaller,py2exe和cx_freeze來運行它。無法在Windows上運行pygame腳本
我的主要問題是,我不確定這個問題到底是什麼。例如:當我像正常一樣運行腳本(使用python而沒有其他)時,腳本打開一個cmd窗口,但立即關閉它,但是當我第一次嘗試將它轉換爲一個.exe文件時,我收到一個錯誤,提示該文件有效,但是對於另一種機器類型(非常確定這與32位和64位python有關,但我不知道如何解決它),並且當我從cmd運行它時,出現錯誤提示沒有名爲pygame的模塊。 我也注意到,當簡單地傳遞原始game.py文件時,一些代碼似乎變得混亂起來,併成爲一條直線(我忘記了這個錯誤的原因是什麼)。
下面是遊戲中我試圖運行整個代碼:
import sys, pygame, pygame.mixer, time
from pygame.locals import *
pygame.init()
pygame.mouse.set_visible(0)
w = 1
while w == 1:
for event in pygame.event.get():
if event.type == KEYDOWN and event.key == K_ESCAPE:
sys.exit()
elif event.type == pygame.QUIT:
sys.exit()
shotgunsound = pygame.mixer.Sound("shotgun.wav")
size = width, height = 600,400
screen = pygame.display.set_mode(size)
bird = pygame.image.load("bird.png")
shotgun = pygame.image.load("fps_sprite_shotgun.png")
post = pygame.image.load("post.png")
ground = pygame.image.load("ground.png")
text2 = pygame.image.load("text2.png")
pygame.display.flip()
skyblue = 0,125,200
x = 0
y = 100
screen.blit(bird,(x,y))
z = 1
while z == 1:
mx,my = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == KEYDOWN and event.key == K_ESCAPE:
sys.exit()
elif event.type == MOUSEBUTTONDOWN and mx > 400 and mx < 560 and my >100 and my <300:
shotgunsound.play()
z = 0
elif event.type == MOUSEBUTTONDOWN:
shotgunsound.play()
screen.fill(skyblue)
screen.blit(bird,(x,y))
screen.blit(shotgun,(mx-300,my-200))
screen.blit(post,(400,100))
screen.blit(ground,(0,0))
pygame.display.flip()
x = x+1
time.sleep(.01)
if x == 400:
screen.blit(text2,(0,0))
pygame.display.flip()
time.sleep(3)
sys.exit()
text1 = pygame.image.load("text1.png")
screen.blit(text1, (0,0))
pygame.display.flip()
n = 1
while n == 1:
for event in pygame.event.get():
if event.type == KEYDOWN and event.key == K_ESCAPE:
sys.exit()
elif event.type == pygame.QUIT:
sys.exit()
if event.type == MOUSEBUTTONDOWN:
n = 0
x = 0
rpg = pygame.image.load("fps_sprite_rpg.png")
w = 0
mx,my = pygame.mouse.get_pos()
t = 1
mx,my = pygame.mouse.get_pos()
green = 0,100,0
building = pygame.image.load("building.png")
rpgsound = pygame.mixer.Sound("rpg.wav")
while t ==1:
mx,my = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == KEYDOWN and event.key == K_ESCAPE:
sys.exit()
elif event.type == pygame.QUIT:
sys.exit()
elif event.type == MOUSEBUTTONDOWN and mx > 400 and mx < 600 and my > 100 and my < 300:
rpgsound.play()
t = 0
elif event.type == MOUSEBUTTONDOWN:
rpgsound.play()
screen.fill(green)
screen.blit(bird,(x,y))
screen.blit(building,(400,50))
screen.blit(rpg,(mx-300,my-200))
x = x+1
pygame.display.flip()
if x == 400:
screen.blit(text2,(0,0))
pygame.display.flip()
time.sleep(3)
sys.exit()
final = pygame.image.load("FINAL.png")
screen.blit(final,(0,0))
pygame.display.flip()
time.sleep(3)
sys.exit()
任何幫助或者標識的問題,甚至幫我解決這些問題將高度讚賞。
你真的在計算機上安裝了'pygame'嗎? – MattDMo
也許是因爲你有幾個while循環和事件循環。 –
我在安裝pygame時遇到了問題,但我認爲它已安裝。當我運行轉換後的exe文件時,它也應該無所謂,因爲即使沒有安裝python也應該可以運行。 – gxt