使用 pyinstaller 编译后 Python 代码无法正常工作



我试图将我的tcountdown.py编译成pyinstaller.exe文件。我读了一些手册,看了YouTube上的教程,都说了同样的话(我确实这么做了):[cmd: c:/**/*>pyinstaller --onefile -w -F tcountdown.py]。CMD与.py的路径相同,它编译一个.exe文件。但是当我运行tcountdown.exe时,它不会启动tpopup。当我用cmd运行tcountdown.py时,一切都很好。我还将tpopup编译为.exe,以检查是否有问题,但这也没有问题。

tcountdown.py:

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

mainscript: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.

最新更新