打包一个简单python文件,过程没问题,运行EXE报错

测试代码


if __name__ == '__main__':
    print("求和小程序")
    a = input("请输入第一个数:")
    b = input("请输入第二个数:")
    print()
    c = int(a) + int(b)
    print("两数之和为:", c)
    input()

打包代码


pyinstaller -cF calculator.py

报错代码


 PYTHONHOME = 'C:\Users\ADMINI~1\AppData\Local\Temp\_MEI39522'
  PYTHONPATH = (not set)
  program name = 'E:\pg\dist\dist\cal.exe'
  isolated = 0
  environment = 0
  user site = 0
  import site = 0
  sys._base_executable = 'E:\\pg\\dist\\dist\\cal.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'E:\\pg\\dist\\dist\\cal.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\_MEI39522\\base_library.zip',
    'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\_MEI39522',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: utf-8

Current thread 0x00000e80 (most recent call first):
<no Python frame>

初学者水平很差,找不到问题所在

检查一下你的py文件是不是utf-8编码

第一行加上,

#coding=utf-8

用笔记本打开这个文件,另存为的时候看看编码是ANSI还是UTF-8