python 使用 pyinstaller 编译后代码无法正常运行

python code doesn't work correctly after compiling with pyinstaller

我正在尝试使用 pyinstaller 将我的 tcountdown.py 编译成 .exe 文件。我已经阅读了一些手册并观看了有关它的 YouTube 教程,并且都说了同样的话(我做了):[cmd: c:/**/*>pyinstaller --onefile -w -F tcountdown.py]。 cmd 与 .py 的路径相同,它编译一个 .exe 文件。但是当我 运行 tcountdown.exe 它不会启动 tpopup。当我 运行 tcountdown.py 使用 cmd 时一切正常。我还只将 tpopup 编译成 .exe 来检查它是否有问题,但这也没有问题。

tcountdown.py:

import os
import time

time.sleep(10)
os.system('tpopup.py')

主程序:tcountdown.py

辅助脚本:tpopup.py

Python 版本为 3.9.1

我认为您需要编辑 tpopup.py 以便它具有您需要进行的任何设置,就像您进行设置一样:

# your setup code goes where it was here

然后,把剩下的代码放到一个函数中,比如:

def open_popup(maybe_with_arguments):
    # rest of the code here

然后在tcountdown中,可以使用

import tpopup # with import, you don't need to compile tpopup - you just need to make sure it's in the same directory as tcountdown.py and pyinstaller should notice it and pack it into the .exe
import time
time.sleep(10) # waiting
tpopup.open_popup(possible_arguments) # calls the code that actually calls the popup, opening the popup AFTER the wait has been completed.