pyinstaller打包py文件时出现错误SyntaxError: Non-UTF-8 code starting with '\xb3'

安装pyinstaller之后用的时候出现了这个问题

 File "C:\Users\陈风\AppData\Local\Programs\Python\Python37-32\Scripts\pyinstaller-script.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xb3' in file C:\Users\陈风\AppData\Local\Programs\Python\Python37-32\Scripts\pyinstaller-script.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

于是打开对应的.py文件发现是这样子的。

#!c:\users\³Â·ç\appdata\local\programs\python\python37-32\python.exe
# EASY-INSTALL-ENTRY-SCRIPT: 'PyInstaller==3.4','console_scripts','pyinstaller'
__requires__ = 'PyInstaller==3.4'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
    )

  1. 可以注意到第一行出现了乱码,我这里对应位置是中文 陈风
    将中文乱码改成对应中文,并在utf-8下编码,发现还是不行
    fail to created process
  2. 在首行加上# -*- coding:utf-8 -*-
    这时候打包就成功了。

问题解决。
欢迎访问陈风的个人博客

你可能感兴趣的:(python)