使pyinstaller可执行文件找到自己的名字?

问题描述 投票:1回答:1

如何使用pyinstaller编译可执行文件找到自己的名字?我需要这个让它自己复制到启动。或者有另一种方法来实现这一目标吗?

file只查找脚本的原始名称,而不是可执行文件。

python python-2.7 startup pyinstaller
1个回答
0
投票

希望这能解决你的问题

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__)
© www.soinside.com 2019 - 2024. All rights reserved.