Python 尝试转换py文件时Pyinstaller出错?

Python 尝试转换py文件时Pyinstaller出错?,python,error-handling,pygame,exe,Python,Error Handling,Pygame,Exe,我正在尝试获取一个Python文件,并使用Pyinstaller将其转换为exe文件。但是,当我这样做时,我会得到一个错误,即: 无法执行python脚本 以下是pygame代码: 导入pygame pygame.init() clock=pygame.time.clock() screen=pygame.display.set_模式((400300)) pygame.display.set_标题(“自动迷宫!”) myfont=pygame.font.SysFont(“Arial”,13)

我正在尝试获取一个Python文件,并使用Pyinstaller将其转换为exe文件。但是,当我这样做时,我会得到一个错误,即:

无法执行python脚本

以下是pygame代码:


导入pygame
pygame.init()
clock=pygame.time.clock()
screen=pygame.display.set_模式((400300))
pygame.display.set_标题(“自动迷宫!”)
myfont=pygame.font.SysFont(“Arial”,13)
x、 y=168100
gameover=False
gameover2=False
完成=错误
虽然没有这样做:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
完成=正确
如果event.type==pygame.MOUSEBUTTONDOWN:
如果游戏结束:
如果按钮1.碰撞点(事件位置):
gameover=False
gameover2=gameover
x、 y=168100
屏幕填充((0,0,0))
“”“试试看:
断言player.collide rect(wall1)
除断言错误外:
通过
除名称错误外:
通过
其他:
死亡屏幕=pygame.display.set_模式((400300))
button1=pygame.draw.rect(死亡屏幕,(0,0,255),(200,200,30,30))
如果没有:
打破
如果没有结束:
pressed=pygame.key.get_pressed()
如果按下[pygame.K_w]:
y-=5
埃利夫按下[pygame.K_s]:
y+=5
埃利夫按下[pygame.K_a]:
x-=5
埃利夫按下[pygame.K_d]:
x+=5
player=pygame.draw.rect(屏幕,(0,255,0),(x,y,60,60))
wall1=pygame.draw.rect(屏幕,(255,0,0)、(400,0,-150,300))
wall2=pygame.draw.rect(屏幕,(255,0,0),(0,0,150300))
如果player.collide rect(墙1):
gameover=True
elif player.Collide Rect(墙2):
gameover=True
其他:
gameover=False
其他:
button1=pygame.draw.rect(屏幕,(0,0255)、(175100,60,30))
text=myfont.render(“重试”,False,(255,0,0))
屏幕显示(文本,(176107))
pygame.display.flip()
时钟滴答(60)
退出
下面是我键入的转换文件的内容:

pyinstaller--onefile-w“import pygame”.py

另外,如果有更好的Pyinstaller替代品,请告诉我。我听说Pyinstaller不是最好的


我的操作系统是Windows 10。

您需要将pyinstaller指向.py文件,而不是.py文件的第一行。 例如,如果文件名为example.py,则需要编写

pyinstaller --onefile -w example.py

pyinstaller--onefile-w your_file.py
在我的文件名中,没有下划线。我尝试了这个,但它说找不到该文件。我的python文件名为import pygame.py这是我的文件的字面名称,然后您应该调用
pyinstaller--onefile-w“import pygame.py”