简体   繁体   English

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

[英]Python cx_Freeze - One Executable file does not open the other?

tss.py --> this file contains a subprocess that open another python file (dark.py) tss.py->此文件包含一个子进程,该子进程可打开另一个python文件(dark.py)

import subprocess as sp

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

process()

This functions works when i execute it as a .py file on the console. 当我在控制台上将其作为.py文件执行时,此功能有效。 However, when I create 2 Executable form (tss.exe and dark.exe) using cx_Freeze and open tss.exe, it does not open the other dark.exe file. 但是,当我使用cx_Freeze创建2个可执行形式(tss.exe和dark.exe)并打开tss.exe时,它不会打开另一个dark.exe文件。

below is the setup.py file used to build the python file: 以下是用于构建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")])

Thankyou 谢谢

Try renaming fileName = "dark.py" to fileName = "dark.exe" in your script. 尝试在脚本fileName = "dark.exe" fileName = "dark.py"重命名为fileName = "dark.exe"

Remember that that you are converting your .py file into an executable format ie .exe so you must launch your exe file not a .py file that will not work on another computer. 请记住,您正在将.py文件转换为可执行格式,即.exe,因此您必须启动exe文件而不是无法在另一台计算机上运行的.py文件。

So it should look like: 所以它应该看起来像:

import subprocess as sp

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

process()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM