Python 3.5 + PyInstaller 3.2.1打包exe出错,TypeError: read() takes no keyword arguments

     Python脚本发布为脱离Python平台运行的可执行程序,比如单个的exe文件,PyInstaller是一个好的选择。


安装了 Python 3.5 + PyInstaller 3.2.1,py文件使用了UTF-8无BOM保存,打包exe时出现下面的错误:

Traceback (most recent call last):
  File "D:\code\Python\Python35-32\Scripts\pyinstaller-script.py", line 11, in 
    load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "", line 28, in 
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\building\api.py", line 388, in __init__
    self.console, self.uac_admin, self.uac_uiaccess)
  File "D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\utils\win32\winmanifest.py", line 1076, in create_manifest
    old_xml = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 172: illegal multibyte sequence

        按提示打开文件:D:\code\Python\Python35-32\lib\site-packages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\utils\win32\winmanifest.py,找到1076行附近:

1074    if not need_new:
1075        with open(filename) as f:
1076            old_xml = f.read()
1077        new_xml = manifest.toprettyxml().replace('\r','')
1078
1079        # this only works if PYTHONHASHSEED is set in environment
1080       need_new = (old_xml != new_xml)

      将其中的1075行改为:

1075        with open(filename,encoding="UTF-8") as f:


       再次打包exe,这次正常无问题。

22163 INFO: checking EXE
22164 INFO: Building EXE because out00-EXE.toc is non existent
22164 INFO: Building EXE from out00-EXE.toc
22165 INFO: Appending archive to EXE Z:\dist\文件对话框.exe
22201 INFO: Building EXE from out00-EXE.toc completed successfully.

-

你可能感兴趣的:(计算机维护)