用pyinstaller打包遇到一个路径的问题, 比如程序要
def get_resource_path(rsfile):
return os.path.join(getattr(sys, '_MEIPASS', os.path.abspath('.')), rsfile)#这里打包后路径变成C:\Users\~\AppData\Local\Temp\_MEIXXXX\,导致找不到文件
修改为如下代码后exe可以正常在当前目录下找到对应的文件
def get_resource_path(rsfile):
application_path = ''
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
return os.path.join(application_path, rsfile)