如何使用pyinstaller编译可执行文件找到自己的名字?我需要这个让它自己复制到启动。或者有另一种方法来实现这一目标吗?
file只查找脚本的原始名称,而不是可执行文件。
希望这能解决你的问题
import os
import sys
# uncompiled file.py can be found by
file_name = os.path.basename(__file__)
# compiled file.exe can find itself by
file_name = os.path.basename(sys.executable)
# and path to py or exe
current_path = os.path.realpath(sys.executable)
current_path = os.path.realpath(__file__)