PyInstaller单文件Exe找不到python310.dll报错求助
PyInstaller单文件打包报错:找不到python310.dll
我查阅了多篇同类技术帖子,没找到和我当前问题匹配的内容。我写了一个调用外部图片、使用pygame.freetype模块的简短Python脚本,相关配置和代码修改都已完成,PyInstaller生成的普通可执行文件在本地及其他电脑都能正常运行,但构建单文件(onefile)版本时,始终出现找不到python310.dll的错误——这个文件本该被打包进Exe,不需要从外部查找。以下是我的Python脚本及.spec文件,麻烦帮忙排查问题:
Python脚本代码
import os import sys import pygame pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode([800, 600]) def resource_path(relative_path): try: base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) splash_image = pygame.image.load(resource_path("chef_full.png")) screen.blit(splash_image, (5,5)) font = pygame.freetype.Font(None, 24) text = "Press 'Esc' to quit." text_rect = font.get_rect(text) text_rect.center = (400, 450) text_rect = font.render_to(screen, text_rect, text, "white") pygame.display.flip() playing = True while playing: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: playing = False elif event.type == pygame.QUIT: playing = False clock.tick(30) pygame.quit()
.spec文件代码
# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['splash.py'], pathex=[], binaries=[], datas=[('chef_full.png', '.')], # A png we use. hiddenimports=['pygame.freetype'], # For display on screen hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, [], exclude_binaries=False, # Don't exclude for onefile builds name='splash', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, ) # Skip collect for onefile #coll = COLLECT( # exe, # a.binaries, # a.zipfiles, # a.datas, # strip=False, # upx=True, # upx_exclude=[], # name='splash', #)
内容的提问来源于stack exchange,提问作者HumanJHawkins
相关产品推荐
相关产品推荐

