Python cx_Freeze - 一个可执行文件无法打开另一个?

时间:2018-02-08 13:45:55

标签: python executable cx-freeze

tss.py - >此文件包含一个打开另一个python文件(dark.py)

的子进程
import subprocess as sp

def process():
    programName = "python.exe"
    fileName = "dark.py"
    sp.Popen([programName, fileName])

process()

当我在控制台上将其作为.py文件执行时,此功能有效。但是,当我使用cx_Freeze创建2个可执行文件(tss.exe和dark.exe)并打开tss.exe时,它不会打开另一个dark.exe文件。

下面是用于构建python文件的setup.py文件:

from cx_Freeze import setup, Executable
import sys
import os

tclDLL = r'C:\Users\Username\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll'
tkDLL = r'C:\Users\Username\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll'

Packages = ["subprocess","tkinter"]
Include_Files = ["icon.ico", "dark.ico",tclDLL, tkDLL]

build_exe_options = {"packages": Packages, "include_files": Include_Files}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

os.environ['TCL_LIBRARY'] = r'C:\Users\Username\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Username\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'

setup(  name = "TSS",
        version = "1.0",
        description = "Tournament Scoring System",
        options = {"build_exe": build_exe_options},
        executables = [Executable("tss.py", base=base, icon="icon.ico")
                       Executable("dark.py", base=base, icon="dark.ico")])

三江源

1 个答案:

答案 0 :(得分:2)

尝试在脚本中将fileName = "dark.py"重命名为fileName = "dark.exe"

请记住,您正在将.py文件转换为可执行格式,即.exe,因此您必须启动您的exe文件,而不是在另一台计算机上无法运行的.py文件。

所以看起来应该是这样的:

import subprocess as sp

def process():
    fileName = "dark.exe"
    sp.call(fileName)

process()