Python 如何修复仅在一台计算机上运行的Exe文件
我已经在pygame上创建了一个基本屏幕,并希望将其编译后作为测试发送给朋友,该文件在我的计算机上运行良好 然而,在我朋友的电脑上,它不运行 他在电脑上没有python或pygame的版本,我使用的是Pycharm项目解释器,只安装了pygame和cx_Freeze 游戏代码Python 如何修复仅在一台计算机上运行的Exe文件,python,pygame,cx-freeze,Python,Pygame,Cx Freeze,我已经在pygame上创建了一个基本屏幕,并希望将其编译后作为测试发送给朋友,该文件在我的计算机上运行良好 然而,在我朋友的电脑上,它不运行 他在电脑上没有python或pygame的版本,我使用的是Pycharm项目解释器,只安装了pygame和cx_Freeze 游戏代码 import sys, pygame size = 600, 600 pygame.init() screen = pygame.display.set_mode(size) colour = (70, 70, 70
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
)
生成文件
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,所以他们可能也没有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或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',
]
将绝对路径更改为相对路径。将绝对路径更改为相对路径。