ubuntu22 python2 pyinstaller 打包报错:'NoneType' object has no attribute 'groups'
前言
最近有个需求,需要在 ubnutu22 上使用 pyinstaller 打包一个python2 的文件。
中间遇到了一些问题:
- pip2 install pyinstaller 报错
解决方案:
pip2 install pyinstaller == 3.6
- 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,很难忘的过程,在此记录,以做参考。
ubuntu22 python2 pyinstaller 打包报错:'NoneType' object has no attribute 'groups'的更多相关文章
- 在Python中使用moviepy进行视频剪辑时输出文件报错 ‘NoneType‘ object has no attribute ‘stdout‘问题
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 movipy输出文件时报错 'NoneType' ...
- Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'
pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...
- python打包--pyinstaller打包报错
先来一段报错信息 目前打包主要涉及socket模块出现的报错 missing module named resource - imported by posix, C:\Users\Administ ...
- 完美解决pyinstaller 打包报错找不到依赖pypiwin32 或pywin32-ctypes的错误
报错信息 最近闲来无事,用python的tkinter库开发了一款带日程提醒的万年历桌面程序.在程序开发结束开始打包时,却发现一直报错 PyInstaller cannot check for ass ...
- python报错Nonetype object is not iterable
https://www.cnblogs.com/zhaijiahui/p/8391701.html 参考链接:http://blog.csdn.net/dataspark/article/detail ...
- 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7
最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...
- pyinstaller打包报错:AttributeError: 'str' object has no attribute 'items'
导致原因和python多数奇奇怪怪的问题一样,依赖包的版本问题. 解决办法: 对setuptools这个包进行升级,链接在这里 https://pypi.org/project/setuptools/ ...
- pyinstaller打包报错: RecursionError: maximum recursion depth exceeded 已经解决
看上去似乎是某个库自己递归遍历超过了python的栈高度限制 搜索了一番,很快找到了解决办法: https://stackoverflow.com/questions/38977929/pyinsta ...
- 报错 'dict' object has no attribute 'has_key'
has_key方法在python2中是可以使用的,在python3中删除了. 比如: if dict.has_key(word): 改为: if word in dict:
- 'NoneType' object has no attribute '__getitem__'
报错 'NoneType' object has no attribute '__getitem__' 你 result 返回的是 None ,所以 result [0] 取不了值
随机推荐
- elasticsearch02-Request Body深入搜索
目录 02. Request Body深入搜索 1.1 term查询 1.1.1 term 与 terms 1.1.2 range 范围查询 1.1.3 Constant Score 1.2 全文查询 ...
- linux开发vue项目,不能热更新?
只需要运行下面的命令即可: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo ...
- C++:面向对象
文章目录 继承与多态 继承 继承的构造与析构 虚继承 多态 ❀虚/纯虚函数❀ 虚析构/纯虚析构 对象的生命周期 实例化对象 构造函数与析构函数 拷贝构造函数 防止拷贝 总结 深拷贝与浅拷贝 初始化列表 ...
- C 语言编程 — 高级数据类型 — 共用体
目录 文章目录 目录 前文列表 共用体 定义共用体 访问共用体成员 前文列表 <程序编译流程与 GCC 编译器> <C 语言编程 - 基本语法> <C 语言编程 - 基本 ...
- Clip-跳过
在 Stable Diffusion 1.x 模型中,CLIP 用作文本嵌入.CLIP模型由多层组成.他们一层一层地变得更加具体.过于简单化,第一层可以理解"人",第二层可以区分& ...
- JS 实现鼠标框选(页面选择)时返回对应的代码或文本内容
JS 实现鼠标框选(页面选择)时返回对应的代码或文案内容 一.需求背景 1.项目需求 当用户进行鼠标框选选择了页面上的内容时,把选择的内容进行上报. 2.需求解析 虽然这需求就一句话的事,但是很显然, ...
- C# WPF 自定义Main方法总结
在使用自定义的Main函数启动应用时,应该需要做这几步: 1.去掉App.xaml的Application的starup属性. 2.右键App.xaml,属性 把生成操作改为Page. 3.如果有引入 ...
- 二进制安装Kubernetes(k8s)v1.30.1
二进制安装Kubernetes(k8s)v1.30.1 https://github.com/cby-chen/Kubernetes 开源不易,帮忙点个star,谢谢了 介绍 kubernetes(k ...
- C#命令行参数解析库System.CommandLine介绍
命令行参数 平常在日常的开发过程中,会经常用到命令行工具.如cmd下的各种命令. 以下为sc命令执行后的截图,可以看到,由于没有输入任何附带参数,所以程序并未执行任何操作,只是输出了描述和用法. 系统 ...
- springboot~封装依赖引用包jar还是pom,哪种更规范
将多个第三方包封装成一个项目后,如果你的目的是让其他开发人员可以直接引用这些依赖,一般来说有两种常见的方式: 打成JAR包:将封装好的项目编译打包成JAR文件,其他开发人员可以将这个JAR文件添加到他 ...