首页 > 解决方案 > Pyinstaller 抛出 AttributeError:“NoneType”对象没有属性“组”错误

问题描述

我正在尝试使用pyinstaller. 该脚本仅使用pandaspdfminer打包。我还创建了一个新环境,只安装了这两个包及其依赖项。运行时出现以下错误pyinstaller --onefile ema_pdf_reader.spec,我的.spec文件如下所示:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['ema_pdf_reader.py'],
             pathex=['/home/erik/PycharmProjects/simple_gui'],
             binaries=[],
             datas=[],
             hiddenimports=['pandas','pdfminer'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='ema_pdf_reader',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

错误:

(clean_env) [erik@liara simple_gui]$ pyinstaller --onefile ema_pdf_reader.spec 
34 INFO: PyInstaller: 3.6
34 INFO: Python: 3.8.2 (conda)
69 INFO: Platform: Linux-5.10.15-1-MANJARO-x86_64-with-glibc2.10
72 INFO: UPX is not available.
73 INFO: Extending PYTHONPATH with paths
['/home/erik/PycharmProjects/simple_gui',
 '/home/erik/PycharmProjects/simple_gui']
73 INFO: checking Analysis
73 INFO: Building Analysis because Analysis-00.toc is non existent
73 INFO: Initializing module dependency graph...
74 INFO: Caching module graph hooks...
78 INFO: Analyzing base_library.zip ...
2247 INFO: Processing pre-find module path hook   distutils
2247 INFO: distutils: retargeting to non-venv dir '/home/erik/miniconda3/envs/clean_env/lib/python3.8'
4327 INFO: Caching module dependency graph...
4424 INFO: running Analysis Analysis-00.toc
4448 INFO: Analyzing ema_pdf_reader.py
5378 INFO: Processing pre-safe import module hook   six.moves
6929 INFO: Processing pre-find module path hook   site
6929 INFO: site: retargeting to fake-dir '/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/fake-modules'
12802 INFO: Processing module hooks...
12802 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
12803 INFO: Loading module hook "hook-numpy.py"...
12803 INFO: Loading module hook "hook-pytz.py"...
12816 INFO: Loading module hook "hook-pandas.py"...
13457 INFO: Loading module hook "hook-distutils.py"...
13459 INFO: Loading module hook "hook-pkg_resources.py"...
13672 INFO: Processing pre-safe import module hook   win32com
13879 WARNING: Hidden import "pkg_resources.py2_warn" not found!
13881 INFO: Excluding import '__main__'
13882 INFO:   Removing import of __main__ from module pkg_resources
13883 INFO: Loading module hook "hook-pydoc.py"...
13883 INFO: Loading module hook "hook-_tkinter.py"...
13974 INFO: checking Tree
13979 INFO: checking Tree
13983 INFO: Loading module hook "hook-sysconfig.py"...
13993 INFO: Loading module hook "hook-cryptography.py"...
14149 INFO: Loading module hook "hook-setuptools.py"...
14570 INFO: Loading module hook "hook-encodings.py"...
14619 INFO: Loading module hook "hook-lib2to3.py"...
14621 INFO: Loading module hook "hook-sqlite3.py"...
14665 INFO: Loading module hook "hook-numpy.core.py"...
14666 INFO: MKL libraries found when importing numpy. Adding MKL to binaries
14667 INFO: Loading module hook "hook-xml.py"...
14790 INFO: Looking for ctypes DLLs
Traceback (most recent call last):
  File "/home/erik/miniconda3/envs/clean_env/bin/pyinstaller", line 11, in <module>
    sys.exit(run())
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "ema_pdf_reader.spec", line 6, in <module>
    a = Analysis(['ema_pdf_reader.py'],
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 244, in __init__
    self.__postinit__()
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/building/datastruct.py", line 160, in __postinit__
    self.assemble()
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 440, in assemble
    ctypes_binaries = scan_code_for_ctypes(co)
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/depend/utils.py", line 143, in scan_code_for_ctypes
    binaries = _resolveCtypesImports(binaries)
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/depend/utils.py", line 317, in _resolveCtypesImports
    load_ldconfig_cache()
  File "/home/erik/miniconda3/envs/clean_env/lib/python3.8/site-packages/PyInstaller/depend/utils.py", line 400, in load_ldconfig_cache
    path = m.groups()[-1]
AttributeError: 'NoneType' object has no attribute 'groups'

我是否需要在我的 .spec 文件中指定一些其他设置?到目前为止,我只是将外部包添加到 hiddenimports,.spec 文件的其余部分是自动生成的 pyi-makespec --onefile ema_pdf_reader.py

它自己的脚本运行良好,创建仅使用标准库的独立脚本也没有问题。

更新 1:

该错误必须是由于 ctype DLL 检测引起的。导入 numpy 时也会发生这种情况。我尝试过使用不同版本的 pyinstaller(3.6 和 4.2),但错误仍然存​​在。我还尝试使用 pip 而不是 conda 重新安装 pyinstaller,但没有帮助。

更新 2: 在 Windows 机器上执行相同的过程按预期工作

标签: pythonlinuxpandaspyinstallerpdfminer

解决方案


似乎在这里(https://github.com/pyinstaller/pyinstaller/issues/5552)他们发现了类似的东西。他们的设置与我的非常相似。还在读...

编辑1: 我终于让它工作了。必须:

1.-编辑手动文件“utils.py”并添加缺少的条件

2.-重新安装我的 Python (3.7.4) 版本并启用共享库

最后的结果还是要测试的。


推荐阅读