pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)相关的知识,希望对你有一定的参考价值。

pyinstaller打包任何py文件TypeError: an integer is required (got type bytes) 

目录

pyinstaller打包任何py文件TypeError: an integer is required (got type bytes) 

现象

原因

解决


现象

# TypeError: an integer is required (got type bytes) 

PS C:\\Users\\sl4v\\Desktop\\Projects\\wikia-download-gui> py -m PyInstaller .\\wikia_dl_gui.py --debug=all
104 INFO: PyInstaller: 3.5.dev0+0cbe7fba3
104 INFO: Python: 3.8.0b1
106 INFO: Platform: Windows-10-10.0.17134-SP0
113 INFO: wrote C:\\Users\\sl4v\\Desktop\\Projects\\wikia-download-gui\\wikia_dl_gui.spec
116 INFO: UPX is not available.
118 INFO: Extending PYTHONPATH with paths
['C:\\\\Users\\\\sl4v\\\\Desktop\\\\Projects\\\\wikia-download-gui',
 'C:\\\\Users\\\\sl4v\\\\Desktop\\\\Projects\\\\wikia-download-gui']
119 INFO: checking Analysis
267 INFO: checking PYZ
267 INFO: Building PYZ because PYZ-00.toc is non existent
268 INFO: Building PYZ (ZlibArchive) C:\\Users\\sl4v\\Desktop\\Projects\\wikia-download-gui\\build\\wikia_dl_gui\\PYZ-00.pyz
Traceback (most recent call last):
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\__main__.py", line 118, in <module>
    run()
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\build_main.py", line 844, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "C:\\Users\\sl4v\\Desktop\\Projects\\wikia-download-gui\\wikia_dl_gui.spec", line 18, in <module>
    pyz = PYZ(a.pure, a.zipped_data,
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\api.py", line 98, in __init__
    self.__postinit__()
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\api.py", line 128, in assemble
    self.code_dict = {
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\api.py", line 129, in <dictcomp>
    key: strip_paths_in_code(code)
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\utils.py", line 652, in strip_paths_in_code
    consts = tuple(
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\utils.py", line 653, in <genexpr>
    strip_paths_in_code(const_co, new_filename)
  File "C:\\Users\\sl4v\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\building\\utils.py", line 660, in strip_paths_in_code
    return code_func(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize,
TypeError: an integer is required (got type bytes)

原因

python的版本与pyinstaller的版本不对应,其中一个过高或者过低引起上面的问题;

例如:

python 3.8.5 和 pyinstall 3.5就会出现如上的问题

解决

所以笔者使用另外一个python版本为python 3.7的环境进行实验就没有了上面的问题:

(base) D:\\python_toexe>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

打包成功:

参考:TypeError: an integer is required (got type bytes) when compiling any script #4265

以上是关于pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)的主要内容,如果未能解决你的问题,请参考以下文章

使用pyinstaller打包.py程序

详解python文件打包成exe(pyinstaller简介.安装.打包.常见问题)

用pyinstall打包.py文件

python桌面应用(pyinstaller打包多个py文件)

pyinstaller---将py文件打包成exe

使用vs2019和pyinstaller将py文件打包成一个exe文件(含图标),pyinstaller安装失败解决方案