notimplementederror:无法对未注册的加载器类型python执行此操作:尝试使用cx_freeze将py转换为.exe [英] notimplementederror: can't perform this operation for unregistered loader type python : trying to convert py to .exe using cx_freeze
本文介绍了notimplementederror:无法对未注册的加载器类型python执行此操作:尝试使用cx_freeze将py转换为.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将pygame项目转换为可执行文件,并且在启动时工作正常,但是当我单击播放"按钮时,它将产生此错误,并且我不确定如果有人可以帮助我,那么该如何解决该问题
I'm trying to convert a pygame project to an executable and it works fine on launch but when I clicked the play button it produces this error and I'm not sure how to fix it would be obliged if anyone could help me
import cx_Freeze
executables = [cx_Freeze.Executable("Consumo V25.py")]
cx_Freeze.setup(
name = "Consumo",
options ={"build_exe": {"packages":["pygame",_init_.py],
"include_files":["Blowfish.png", "dojo.png", "Rice_fresh.png", "rottenapple.png", "rottenfish.png", "rottenrice.png", "gameover.png", "Apple .png", "Fish.png","sumo .png","character.png"]}},
executables = executables
)
这是我的源代码中的按钮功能:
Here is the button function that is in my source code:
def button(msg,x,y,w,h,c,action=None):#passes the parameters by value
mouse = pygame.mouse.get_pos()#this gets the postion of the mouse
click = pygame.mouse.get_pressed()#checks to see where the mouse has been clicked
pygame.draw.rect(gameDisplay, c,(x,y,w,h))#draws a rectangle with on the game display with the parameters given
if x+w > mouse[0] >x and y+h > mouse[1] > y:#checks to see if the mouse has been clicked anywhere in the button
if click[0] == 1 and action != None:#if the mouse has been clicked performed an action
action()
smallText = pygame.font.SysFont("comicsansMS",20)
textSurf , textRect = textObjects(msg ,smallText)
#sets the message of the button
textRect.center = ((x+(w/2),(y+(h/2))))#centers the text on screen
gameDisplay.blit(textSurf, textRect)#puts the button on screen with the
这是我运行函数的地方:
here is where I'm running the function:
def menuScreen():
screenOn = True
while screenOn ==True:
for event in pygame.event.get():
if event.type == pygame.QUIT:#allows user to quit the game
quit()
gameDisplay.blit(dojoBackDrop,(0,0))#sets the image to the size of the screen
button("Play Game",850,340,120,50,blue,gameLoop)#Puts theree button on the screen
button("Leaderboard",850,440,120,50,blue)
button("Quit game",850,540,120,50,blue,quitGame)
pygame.display.update()#updates the screen so things can appear on it
完整错误是:
File "C:\Users\Jackj\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame\pkgdata.py", line 50, in getResource
if resource_exists(pkgname, identifier):
File "C:\Users\Jackj\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\__init__.py", line 1191, in resource_exists
return get_provider(package_or_requirement).has_resource(resource_name)
File "C:\Users\Jackj\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\__init__.py", line 1459, in has_resource
return self._has(self._fn(self.module_path, resource_name))
File "C:\Users\Jackj\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\__init__.py", line 1509, in _has
"Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type
推荐答案
通过替换 C:\ Users \ Jackj \ AppData \ Local的第50到51行,您可以尝试找出导致该异常的资源\ Programs \ Python \ Python36 \ lib \ site-packages \ pygame \ pkgdata.py
具有:
try:
if resource_exists(pkgname, identifier):
return resource_stream(pkgname, identifier)
except Exception as e:
print(pkgname, identifier)
raise e
这篇关于notimplementederror:无法对未注册的加载器类型python执行此操作:尝试使用cx_freeze将py转换为.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文