2023年7月3日发(作者:)
pyinstaller打包后,配置⽂件⽆法正常读取的解决⽬录pyinstaller打包配置⽂件⽆法正常读取pyinstaller⼜踩⼀坑,configparser 完整代码pyinstaller打包配置⽂件⽆法正常读取import osfile = e(h(__file__))cf = Parser()print(file)(file+'/')先获取绝对路径在读取pyinstaller⼜踩⼀坑,configparser 在使⽤pyinstaller时,有使⽤configparser模块。使⽤相对路径。在pycharm中测试,正常,打包成exe,就出错了换⽤绝对路径,print(())fp_dir=()print(fp_dir)fp = fp_dir + '' # 定义配置⽂件名print(fp)基本正常。可是遇到了(fp) # 打开conf _section('conf') # 添加conf节点不能⾃动创建⽂件尝试,windows下根本不⽀持。 tes = open(fp,'a') ()⽤open⽅法,终于调试成功。完整代码def make_conf(): print('make') conf = ConfigParser() # 实例化 print('没有配置⽂件,创建中') tes = open(fp, 'a') () firefox = str(get_extension([''])) geckodriver = str(get_extension([''])) WeChat = str(get_extension([''])) (fp) # 打开conf if type!='up': _section('conf') # 添加conf节点 print('add section') ('conf', 'firefox', firefox) # 添加值 ('conf', 'geckodriver', geckodriver) # 添加值 ('conf', 'wechat', WeChat) # 添加值 # ('conf', 'firefox', '') # 添加值 # ('conf', 'geckodriver', '') # 添加值 # ('conf', 'wechat', '') # 添加值 print('set all', fp) with open(fp, 'w') as fw: # 循环写⼊ (fw) return True以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1688384568a130016.html
评论列表(0条)