pyinstaller打包成exe之后,获取exe路径

 

文件路径  C:\Users\寒寻\Documents\gamefi\createNewETHAddress\createNewETHAddress.py


print(os.path.realpath(sys.argv[0]))

C:\Users\寒寻\Documents\gamefi\createNewETHAddress\createNewETHAddress.py


print(os.path.realpath(sys.executable))

 C:\ProgramData\Anaconda3\envs\gamefi\python.exe


print(os.path.dirname(os.path.realpath(sys.argv[0])))

C:\Users\寒寻\Documents\gamefi\createNewETHAddress


print(os.path.dirname(os.path.realpath(sys.executable)))

C:\ProgramData\Anaconda3\envs\gamefi


如果直接使用__file__,在打包成exe之后是无法获取文件路径的

posted @ 2021-12-21 17:44  寒寻  阅读(581)  评论(0编辑  收藏  举报