首页 > 系统相关 >ubuntu22 python2 pyinstaller 打包报错:'NoneType' object has no attribute 'groups'

ubuntu22 python2 pyinstaller 打包报错:'NoneType' object has no attribute 'groups'

时间:2024-05-09 19:55:07浏览次数:15  
标签:pyinstaller name lib no 报错 usr line local

前言


最近有个需求,需要在 ubnutu22 上使用 pyinstaller 打包一个python2 的文件。

中间遇到了一些问题:

  1. pip2 install pyinstaller 报错
    解决方案:
pip2 install pyinstaller == 3.6
  1. python2 和 python3 的 pyinstaller 如何同时存在,我想把 python2 的 pyinstaller 命名为 pyinstaller2,

把 python3 的 pyinstaller 不重名。

# 如果安装了 python3 的 pyinstaller,需要先卸载
pip3 uninstall pyinstaller

# 1. 安装python2 的 pyinstaller
pip2 install pyinstaller == 3.6
# 2. 找到 pyinstaller 位置 (我的环境是在 /usr/local/bin/pyinstaller)
whereis pyinstaller
# 3. 重命名 python2 的 pyinstaller 为 pyinstaller2
cd /usr/local/bin/
mv pyinstaller pyinstaller2
# 4. 检查
pyinstaller2 --version

# 5. 重新安装 python3 的 pyinstaller
pip3 install pyinstaller

# 6. 检查python3 的 pyinstaller
pyinstaller --version

然后,使用命令,打包出现报错

pyinstaller2 -F tst.py -p /usr/lib/python2.7/dist-packages/
1463 INFO: Python library not in binary dependencies. Doing additional searching...
Traceback (most recent call last):
  File "/usr/local/bin/pyinstaller2", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "/mnt/wallE_code_u22/pytest/pythonApiTst/code_u22/christie3_ctl.spec", line 17, in <module>
    noarchive=False)
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/build_main.py", line 244, in __init__
    self.__postinit__()
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/datastruct.py", line 160, in __postinit__
    self.assemble()
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/build_main.py", line 478, in assemble
    self._check_python_library(self.binaries)
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/building/build_main.py", line 568, in _check_python_library
    python_lib = bindepend.get_python_library_path()
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/depend/bindepend.py", line 915, in get_python_library_path
    python_libname = findLibrary(name)
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/depend/bindepend.py", line 775, in findLibrary
    utils.load_ldconfig_cache()
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/depend/utils.py", line 400, in load_ldconfig_cache
    path = m.groups()[-1]
AttributeError: 'NoneType' object has no attribute 'groups'

下面,将描述我的解决方案

正文


chatgpt 建议使用 sudo ldconfig 刷新共享库缓存,我试了但是还是报上面的错误。

后来 view /usr/local/lib/python2.7/dist-packages/PyInstaller/depend/utils.py 400 行,找到了报错的地方

try:
        text = compat.exec_command(ldconfig, ldconfig_arg)
    except ExecCommandFailed:
        logger.warning("Failed to execute ldconfig. Disabling LD cache.")
        LDCONFIG_CACHE = {}
        return

    text = text.strip().splitlines()[splitlines_count:]
    
    LDCONFIG_CACHE = {}
    for line in text:
        # :fixme: this assumes libary names do not contain whitespace
        m = pattern.match(line)
        path = m.groups()[-1]
        if is_freebsd or is_openbsd:
            # Insert `.so` at the end of the lib's basename. soname
            # and filename may have (different) trailing versions. We
            # assume the `.so` in the filename to mark the end of the
            # lib's basename.
            bname = os.path.basename(path).split('.so', 1)[0]
            name = 'lib' + m.group(1)
            assert name.startswith(bname)
            name = bname + '.so' + name[len(bname):]
        else:
            name = m.group(1)
        # ldconfig may know about several versions of the same lib,
        # e.g. differents arch, different libc, etc. Use the first
        # entry.
        if not name in LDCONFIG_CACHE:
            LDCONFIG_CACHE[name] = path

这里path = m.groups()[-1] 的 m 是个 None 类型,然后 m的来源是 m = pattern.match(line), line 是获取共享库后逐行读取的字段。那就是 m = pattern.match(line) 出现了异常。

打印 m 报错 None 时 line 的值,发现此时 line: 缓存生成方: ldconfig (Ubuntu GLIBC 2.35-0ubuntu3.6) stable release version 2.35, 程序就是在解析这句时报错,原因是格式不匹配。

使用系统指令

sudo ldconfig -p

发现打印的信息最后一行就是:缓存生成方: ldconfig (Ubuntu GLIBC 2.35-0ubuntu3.6) stable release version 2.35

解决方案,修改 utils.py 中的处理过程,略过 m 为 None 的部分


LDCONFIG_CACHE = {}
    for line in text:
        # :fixme: this assumes libary names do not contain whitespace
        m = pattern.match(line)
        
        # brian add 2024-05-09
        if m is None:
            print(line)
            continue
        # brian add end

        path = m.groups()[-1]
        if is_freebsd or is_openbsd:
            # Insert `.so` at the end of the lib's basename. soname
            # and filename may have (different) trailing versions. We
            # assume the `.so` in the filename to mark the end of the
            # lib's basename.
            bname = os.path.basename(path).split('.so', 1)[0]
            name = 'lib' + m.group(1)
            assert name.startswith(bname)
            name = bname + '.so' + name[len(bname):]
        else:
            name = m.group(1)
        # ldconfig may know about several versions of the same lib,
        # e.g. differents arch, different libc, etc. Use the first
        # entry.
        if not name in LDCONFIG_CACHE:
            LDCONFIG_CACHE[name] = path

添加了这个字段

        # brian add 2024-05-09
        if m is None:
            print(line)
            continue
        # brian add end

果然python2 停止维护后,还需要手动修改bug,很难忘的过程,在此记录,以做参考。

标签:pyinstaller,name,lib,no,报错,usr,line,local
From: https://www.cnblogs.com/brian-sun/p/18182979

相关文章

  • Linux nohup 命令
    Linuxnohup命令应用场景使用PyCharm连接服务器跑模型虽然很方便,但是如果遇到网络不佳、PyCharm出BUG、急需转移阵地等情况就只能中断训练,前面的全白跑了。因此可以尝试直接在服务器上使用命令跑模型,这个命令好说,笨一点的方法直接抄用PyCharm运行时输出的命令嘛:但是这样......
  • TextClip构造方法报OSError:MoviePy creation of None failed because of the followi
    在使用moviepy的构造方法创建实例时报错:这可能是两个原因导致的:未安装ImageMagick应用ImageMagick是一套功能强大、稳定而且开源的多平台工具集和开发包,可以用来读、写和处理超过200种基本格式的图片文件,包括PNG,JPEG,GIF,HEIC,TIFF,DPX,EXR,WebP,Postscript,PDF和SVG等格式。利用ImageM......
  • OSX上管理多个版本的Nodejs,并且随意切换
    Nodejs的项目经常Node自身的版本不同而无法运行,如果每次都选择卸载掉一个版本的Nodejs再安装另外一个版本的Nodejs,会很费劲,通过如下命令切换。例如:#Forexample#Installmainnodeversion18$brewinstallnode@18#Addthemainversionto~/.zshrctomakestarte......
  • PCI-Express-Technology(一)
    https://github.com/ljgibbslf/Chinese-Translation-of-PCI-Express-Technology-/blob/main/1%20%E8%83%8C%E6%99%AF.md1.3.2PCI总线发起方(Initiator)与目标方(Target)在PCI层次结构中,总线上的每个设备(device)可以包含多达8个功能(function),这些功能都共享该设备的总线接口,功能......
  • 基于nodeje的RSA加解密
    RAS是一种非对称加密,可以用公钥加密,私钥解密也可以反过来用私钥加密,公钥解密;以下是其实现方式,与java后台匹配,实现双向加解密。/***RSA最大加密明文大小*/constMAX_ENCRYPT_BLOCK=245;/***RSA最大解密密文大小*/constMAX_DECRYPT_BLOCK=256;通过fs.readFil......
  • Error: Cannot find module ‘D:\SoftSetupLoaction\nodejs\node_global\node_mod
    Error:Cannotfindmodule‘D:\SoftSetupLoaction\nodejs\node_global\node_modules\npm\bin\npm-cli.js‘  出现原因:重新安装可装了nodejs和npm网上查了很多方法,都建议重装,但是都没有效果(因为我就是重装之后出现的问题)按照错误提示node_global找不到npm-cli.js,个......
  • 实验1-波士顿房价预测部分报错解决方法
    运行sgd=SGDRegressor()sgd.fit(x_train,y_train)print("r2scoreofLinearregressionis",r2_score(y_test,sgd.predict(x_test)))时出现DataConversionWarning:Acolumn-vectorywaspassedwhena1darraywasexpected.Pleasechangetheshapeofyt......
  • Node.js证件OCR、身份证实名认证接口、身份证识别API
    身份证是证明公民身份的有效证件,一些不法分子可以通过简单的工序制作出假身份证,损害老百姓的合法利益。据警方统计,大部分预谋诈骗犯罪分子会使用假身份证件,而社会上也有一部分人出于不正当的目的,刻意隐瞒自己真实的身份信息。在这种前提下,“全国身份证联网核查”应运而生,它的......
  • 会充电的CANoe-赋能新能源汽车,高效完成即插即充(PnC)智能充电功能测试
     ISO15118-2标准中描述的PnC功能,可以实现插枪即充电,识别、计费信息、充电参数都通过高级别通信在EV和EVSE之间自动交换。简化了电动汽车的充电过程,提高了用户体验,为电动汽车行业带来了更智能、更便捷的充电解决方案。 然而,电动汽车和充电站之间要实现自动通信和计费,必须交......
  • 深度学习tf2.0版本报错——实验24
    深度学习:fromtensorflow.contrib.rnnimportLSTMStateTuple没有contrib模块_indylstm-CSDN博客把原先的tf引用换成蓝色框框,然后把红框的代码改成星星处代码——————针对LSTMCell报错 tf2.0里面缺少crf包是因为把这个contrib包删除了所以要下载一个新的库:安装之后就不会......