【问题标题】:How to fix Exe file only running on one computer如何修复仅在一台计算机上运行的 Exe 文件
【发布时间】:2019-03-29 17:11:23
【问题描述】:

我在pygame上创建了一个基本画面,想编译发给朋友作为测试,文件在我的电脑上完美运行

但是,在我朋友的电脑上,它没有运行。

他的计算机上没有 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
)

【问题讨论】:

  • 将绝对路径改为相对路径。

标签: python pygame cx-freeze


【解决方案1】:

由于您的朋友没有 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',
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2016-12-20
    相关资源
    最近更新 更多