struct.error:'i'格式要求-2147483648 <=数字<= 2147483647,同时使用PyInstaller创建独立的可执行文件

问题描述

我正在尝试使用afSara3.py创建脚本PyInstaller的独立可执行文件。我收到此错误

struct.error:“ i”格式要求-2147483648

但无法弄清楚原因。看来问题是在执行时发生的

建筑PKG(便携式)PKG-00.pkg

我不能提供该脚本,因为不应将该脚本公开。

运行后-

pyinstaller --specpath ./dist --distpath ./dist --workpath ./dist --onefile ./afSara3.py

368 INFO: PyInstaller: 4.0
368 INFO: Python: 3.6.9
377 INFO: Platform: Linux-5.4.0-48-generic-x86_64-with-ubuntu-18.04-bionic
378 INFO: wrote ./dist/afSara3.spec
394 INFO: UPX is not available.
400 INFO: Extending PYTHONPATH with paths
['/home/afSara-ben/Downloads/coding assignment/src','/home/afSara-ben/Downloads/coding assignment/src/dist']
537 INFO: checking Analysis
2786 INFO: Building because /home/afSara-ben/Downloads/coding assignment/src/afSara3.py changed
2786 INFO: Initializing module dependency graph...
2799 INFO: Caching module graph hooks...
2833 INFO: Analyzing base_library.zip ...
6192 INFO: Caching module dependency graph...
6255 INFO: running Analysis Analysis-00.toc
6303 INFO: Analyzing afSara3.py
7149 INFO: Processing pre-find module path hook distutils from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
7181 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.6'
8643 INFO: Processing pre-find module path hook site from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_find_module_path/hook-site.py'.
8650 INFO: site: retargeting to fake-dir '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/fake-modules'
13561 INFO: Processing pre-safe import module hook six.moves from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-six.moves.py'.
23794 INFO: Processing module hooks...
23794 INFO: Loading module hook 'hook-lxml.etree.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
23800 INFO: Loading module hook 'hook-certifi.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
23811 INFO: Loading module hook 'hook-openpyxl.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
23851 INFO: Loading module hook 'hook-pkg_resources.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
24243 INFO: Processing pre-safe import module hook win32com from '/home/afSara-ben/.local/lib/python3.6/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'.
24245 WARNING: Hidden import "pkg_resources.py2_warn" not found!
24245 WARNING: Hidden import "pkg_resources.markers" not found!
24247 INFO: Excluding import '__main__'
24249 INFO:   Removing import of __main__ from module pkg_resources
24249 INFO: Loading module hook 'hook-PIL.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
24259 INFO: Import to be excluded not found: 'PySide'
24259 INFO: Import to be excluded not found: 'tkinter'
24259 INFO: Excluding import 'PyQt4'
24261 INFO: Import to be excluded not found: 'FixTk'
24261 INFO: Excluding import 'PyQt5'
24262 INFO:   Removing import of PyQt5.QtCore from module PIL.ImageQt
24263 INFO:   Removing import of PyQt5.QtGui from module PIL.ImageQt
24263 INFO: Loading module hook 'hook-numpy.core.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
25202 INFO: Loading module hook 'hook-setuptools.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
25889 INFO: Loading module hook 'hook-xml.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
25900 INFO: Loading module hook 'hook-PyQt5.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47189 WARNING: Hidden import "PyQt5.sip" not found!
47189 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47444 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47480 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47481 INFO: Loading module hook 'hook-xml.dom.domreg.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47482 INFO: Loading module hook 'hook-pytz.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47483 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
47572 INFO: Loading module hook 'hook-pandas.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
50178 INFO: Loading module hook 'hook-PIL.Image.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
50845 INFO: Loading module hook 'hook-lib2to3.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
50870 INFO: Loading module hook 'hook-matplotlib.backends.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
52994 INFO:   Matplotlib backend "GTK3Agg": added
53501 INFO:   Matplotlib backend "GTK3Cairo": added
53770 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name '_macosx'
54036 INFO:   Matplotlib backend "nbAgg": ignored
    No module named 'IPython'
-c:12: MatplotlibDeprecationWarning: 
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
54508 INFO:   Matplotlib backend "Qt4Agg": added
-c:12: MatplotlibDeprecationWarning: 
The matplotlib.backends.backend_qt4cairo backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
54934 INFO:   Matplotlib backend "Qt4Cairo": added
55312 INFO:   Matplotlib backend "Qt5Agg": added
55696 INFO:   Matplotlib backend "Qt5Cairo": added
56323 INFO:   Matplotlib backend "TkAgg": added
56752 INFO:   Matplotlib backend "TkCairo": added
57025 INFO:   Matplotlib backend "WebAgg": ignored
    Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg.py",line 27,in <module>
    import tornado
ModuleNotFoundError: No module named 'tornado'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>",line 12,in <module>
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg.py",line 29,in <module>
    raise RuntimeError("The WebAgg backend requires Tornado.") from err
RuntimeError: The WebAgg backend requires Tornado.
57438 INFO:   Matplotlib backend "WX": ignored
    No module named 'wx'
57697 INFO:   Matplotlib backend "WXAgg": ignored
    No module named 'wx'
57970 INFO:   Matplotlib backend "WXCairo": ignored
    No module named 'wx'
58280 INFO:   Matplotlib backend "agg": added
58592 INFO:   Matplotlib backend "cairo": added
59056 INFO:   Matplotlib backend "pdf": added
59466 INFO:   Matplotlib backend "pgf": added
59780 INFO:   Matplotlib backend "ps": added
60112 INFO:   Matplotlib backend "svg": added
60516 INFO:   Matplotlib backend "template": added
60708 INFO: Processing pre-safe import module hook gi.repository.Gio from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.Gio.py'.
60724 INFO: Processing pre-safe import module hook gi.repository.GLib from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GLib.py'.
60725 INFO: Processing pre-safe import module hook gi.repository.GObject from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GObject.py'.
60735 INFO: Processing pre-safe import module hook gi.repository.Gtk from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.Gtk.py'.
60736 INFO: Processing pre-safe import module hook gi.repository.Gdk from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.Gdk.py'.
61248 INFO: Loading module hook 'hook-gi.repository.Gtk.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78487 INFO: Processing pre-safe import module hook gi.repository.xlib from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.xlib.py'.
78492 INFO: Processing pre-safe import module hook gi.repository.Atk from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.Atk.py'.
78509 INFO: Loading module hook 'hook-sqlite3.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78592 INFO: Loading module hook 'hook-numpy.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78593 INFO: Loading module hook 'hook-distutils.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78593 INFO: Loading module hook 'hook-sysconfig.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78611 INFO: Loading module hook 'hook-gi.repository.Gio.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
78878 INFO: Loading module hook 'hook-_tkinter.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
79036 INFO: checking Tree
79047 INFO: checking Tree
79049 INFO: Loading module hook 'hook-matplotlib.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
79322 INFO: Loading module hook 'hook-encodings.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
79506 INFO: Loading module hook 'hook-gi.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
79541 INFO: Loading module hook 'hook-gi.repository.GLib.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
79848 INFO: Loading module hook 'hook-gi.repository.Gdk.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80002 INFO: Processing pre-safe import module hook gi.repository.cairo from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.cairo.py'.
80003 INFO: Processing pre-safe import module hook gi.repository.Pango from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.Pango.py'.
80004 INFO: Processing pre-safe import module hook gi.repository.GdkPixbuf from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GdkPixbuf.py'.
80004 INFO: Loading module hook 'hook-gi.repository.cairo.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80147 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80152 INFO: Import to be excluded not found: 'FixTk'
80152 INFO: Excluding import 'tkinter'
80153 INFO: Loading module hook 'hook-gi.repository.Atk.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80347 INFO: Loading module hook 'hook-gi.repository.GObject.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80506 WARNING: Hidden import "gi._gobject" not found!
80507 INFO: Loading module hook 'hook-gi.repository.xlib.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80632 INFO: Loading module hook 'hook-gi.repository.Pango.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
80777 INFO: Loading module hook 'hook-gi.repository.GdkPixbuf.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
81114 INFO: Processing pre-safe import module hook gi.repository.GModule from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GModule.py'.
81116 INFO: Loading module hook 'hook-gi.repository.GModule.py' from '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks'...
82059 INFO: Looking for ctypes DLLs
82341 WARNING: library user32 required via ctypes not found
82472 WARNING: library msvcrt required via ctypes not found
82491 INFO: Analyzing run-time hooks ...
82505 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgres.py'
82506 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
82509 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth__tkinter.py'
82509 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pyqt5.py'
82510 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_gdkpixbuf.py'
82511 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_gtk.py'
82512 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_glib.py'
82512 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_gio.py'
82513 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_gi.py'
82514 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_mplconfig.py'
82515 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/hooks/rthooks/pyi_rth_mpldata.py'
82515 INFO: Including run-time hook '/home/afSara-ben/.local/lib/python3.6/site-packages/_pyinstaller_hooks_contrib/hooks/rthooks/pyi_rth_certifi.py'
82536 INFO: Looking for dynamic libraries
89670 INFO: Looking for eggs
89670 INFO: Python library not in binary dependencies. Doing additional searching...
89716 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
89733 INFO: Warnings written to ./dist/afSara3/warn-afSara3.txt
89840 INFO: Graph cross-reference written to ./dist/afSara3/xref-afSara3.html
94490 INFO: checking PYZ
94537 INFO: Building because toc changed
94537 INFO: Building PYZ (ZlibArchive) ./dist/afSara3/PYZ-00.pyz
96136 INFO: Building PYZ (ZlibArchive) ./dist/afSara3/PYZ-00.pyz completed successfully.
96443 INFO: checking PKG
96443 INFO: Building PKG because PKG-00.toc is non existent
96443 INFO: Building PKG (CArchive) PKG-00.pkg
Traceback (most recent call last):
  File "/home/afSara-ben/.local/bin/pyinstaller",line 11,in <module>
    sys.exit(run())
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/__main__.py",line 114,in run
    run_build(pyi_config,spec_file,**vars(args))
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/__main__.py",line 65,in run_build
    PyInstaller.building.build_main.main(pyi_config,**kwargs)
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py",line 720,in main
    build(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py",line 667,in build
    exec(code,spec_namespace)
  File "./dist/afSara3.spec",line 33,in <module>
    console=True )
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/api.py",line 437,in __init__
    upx_exclude=self.upx_exclude
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/api.py",line 200,in __init__
    self.__postinit__()
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/datastruct.py",line 160,in __postinit__
    self.assemble()
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/building/api.py",line 285,in assemble
    pylib_name=pylib_name)
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/archive/writers.py",line 332,in __init__
    super(CArchiveWriter,self).__init__(archive_path,logical_toc)
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/archive/writers.py",line 64,in __init__
    self._finalize()
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/archive/writers.py",line 96,in _finalize
    self.save_trailer(toc_pos)
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/archive/writers.py",line 439,in save_trailer
    tocstr = self.toc.tobinary()
  File "/home/afSara-ben/.local/lib/python3.6/site-packages/PyInstaller/archive/writers.py",line 264,in tobinary
    flag,ord(typcd),nm + pad))
struct.error: 'i' format requires -2147483648 <= number <= 2147483647

解决方法

我遇到了同样的问题,并为我找到了以下解决方案:

  1. 使用虚拟环境(您可以遵循this tutorial,其中提供了清晰的说明)。
  2. 修复pandastable和matplotlib(在我的情况下,该错误与pandastable有某种联系,但我不确定哪个是确切的问题。