gpt4 book ai didi

python - 如何修复Exe文件只在一台计算机上运行

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:42 25 4
gpt4 key购买 nike

我在 pygame 上创建了一个基本屏幕,并想编译它并发送给 friend 作为测试,并且该文件在我的计算机上完美运行

但是,在我 friend 的计算机上,它无法运行。

他的计算机上没有 python 或 pygame 版本,而我使用的是仅安装了 pygame 和 cx_Freeze 的 Pycharm 项目解释器

游戏代码

import sys, pygame

size = 600, 600
pygame.init()

screen = pygame.display.set_mode(size)

colour = (70, 70, 70)

while 1:

screen.fill(colour)

for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

pygame.display.update()

构建文件

import cx_Freeze
import os

os.environ['TCL_LIBRARY'] = r'C:\Users\jls45\Documents\Curse\code\BigBossBattleGame\venv\Scripts\tcl86t.dll'
os.environ['TK_LIBRARY'] = r'C:\Users\jls45\Documents\Curse\code\BigBossBattleGame\venv\Scripts\tk86t.dll'

executables = [cx_Freeze.Executable("Main.py")]

cx_Freeze.setup(
name="Test",
options={"build_exe": {"packages":["pygame"],
"include_files":["test.png"]}},
executables = executables
)

最佳答案

由于您的 friend 没有 Python 或 pygame,他们可能也没有 tk/tcl。您需要将这些 .dll 与可执行文件打包在一起。

"include_files":[
"test.png",
r'C:\Users\jls45\Documents\Curse\code\BigBossBattleGame\venv\Scripts\tcl86t.dll',
r'C:\Users\jls45\Documents\Curse\code\BigBossBattleGame\venv\Scripts\tk86t.dll',
]

关于python - 如何修复Exe文件只在一台计算机上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55422414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com