带有子程序的cx_冷冻柜

2024-06-09 00:06:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个问题,我有一个python脚本,当我运行它时运行得很好,但我正在尝试创建一个可执行文件,它会崩溃

setup.py

import sys
from cx_Freeze import setup, Executable
import os 

os.environ['TCL_LIBRARY'] = r'C:\Users\x_sal\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\x_sal\Anaconda3\tcl\tk8.6'

build_exe_options = {"packages": [
    "os",
    "sys",
    "matplotlib",
    "subprocess",
    "serial",
    "numpy",
    "msvcrt",
    "time",
    "dataCollectionE"
    ]}

setup(
    name = "Data Collection",
    version = "1",
    description = "Read data from Arduino",
    options = {"build_exe": build_exe_options},
    executables = [Executable("dataCollection.py")])

dataCollection.py

if __name__ == "__main__":
    fid = fileN()
    dir = os.path.dirname(os.path.abspath(sys.argv[0])))
    cmdline = 'python -c "from dataCollection import printSerial; printSerial() "'
    rc = call("start cmd /K " + cmdline, cwd=dir, shell=True) # run `cmdline` in `dir`
    while fid == fileN():
        time.sleep(1)
    livePlot(dados = "f")

livePlot是一个生成实时绘图的函数,printSerial用于读取COM4。 当我跑的时候

rc = call("start cmd /K " + cmdline, cwd=dir, shell=True)

我的目标是打开一个新的命令窗口并运行它,一旦两个进程不能在同一个cmd中运行。如果我只是运行它,它可以正常工作,但是当它是exe时,它会给出一个错误:

ModuleNotFoundError: No module named 'dataCollection'

如果有人认为其余的代码是相关的,让我知道,因为它是一个有点广泛,我现在不张贴它。 多谢各位


Tags: frompyimportbuildcmdosdirsys