pyinstaller打包遇到的坑【总结】

linux Pyinstaller 打包运行报错 OSError: Cannot load native module ‘Crypto.Cipher._raw_ecb‘: Not found ‘_ra 然后和crypto有关的模块都卸载一遍。最后安装pip3 install pycryptodome。别装别的模块(比如pycrypto、pycryptodomex、 ),没用的只需要pycryptodome。原因是缺少文件hook-Crypto.py文件路径在/usr/local/lib/python3.7/site-packages/PyInstaller/hooks。linux Pyinstaller 打包运行报错。 阅读详情

执行pyinstaller命令后,一般都会在项目根目录生成一个.spec的文件,现在基于该文件进行修改。

Q:为什么不在pyinstaller命令修改?
S:命令修改不直观,且文件中可以执行python代码,方便处理大批量数据

现象1:

出现类似问题,就是项目过大,打包深度超出预设

=============================================================
A RecursionError (maximum recursion depth exceeded) occurred.
For working around please follow these instructions
=============================================================

1. In your program's .spec file add this line near the top::

     import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)

2. Build your program by running PyInstaller with the .spec file as
   argument::

     pyinstaller myprog.spec

3. If this fails, you most probably hit an endless recursion in
   PyInstaller. Please try to track this down as far as possible,
   create a minimal example so we can reproduce and open an issue at
   https://github.com/pyinstaller/pyinstaller/issues following the
   instructions in the issue template. Many thanks.

Explanation: Python's stack-limit is a safety-belt against endless recursion,
eating up memory. PyInstaller imports modules recursively. If the structure
how modules are imported within your program is awkward, this leads to the
nesting being too deep and hitting Python's stack-limit.

With the default recursion limit (1000), the recursion error occurs at about
115 nested imported, with limit 2000 at about 240, with limit 5000 at about
660.

解决:

# .spec文件中添加
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)

现象2:

这个报错是无法加载到Crypto.Cipher相关包的内容导致的

OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-310-x86_64-linux-gnu.so', Not found '_raw_ecb.abi3.so', Not found '_raw_ecb.so'

解决:
参考我的另一篇内容:https://blog.youkuaiyun.com/Types_c/article/details/147380644?spm=1001.2014.3001.5501

现象3:

出现包导入失败的问题

    import sentence_transformers
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "sentence_transformers/__init__.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "sentence_transformers/cross_encoder/__init__.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "sentence_transformers/cross_encoder/CrossEncoder.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "transformers/utils/import_utils.py", line 1955, in __getattr__
  File "transformers/utils/import_utils.py", line 1969, in _get_module
RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback):

解决:
.spec datas 下添加对应的包,例如:
('yourpath/python3.10/site-packages/transformers/models/auto/*','transformers/models/auto/')

现象4:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEItO35DO/transformers/models/aria'

解决:
参考现象3的解决方式,把对应的文件打包到transformers/models/aria文件夹下即可。

现象5:

RuntimeError: Failed to import transformers.models.auto.modeling_auto because of the following error (look up to see its traceback):
Failed to import transformers.generation.utils because of the following error (look up to see its traceback):
No module named 'sklearn.metrics._pairwise_distances_reduction._datasets_pair'

解决:
hiddenimports中添加sklearn.metrics._pairwise_distances_reduction._datasets_pair对应的module,named后就是module的名称,复制添加就行

现象6:(重点)

import requests,大部分人第一时间在hiddenimports添加报错的依赖,都会发现还是报错,在datas和hiddenimport添加了requests也没有解决

    from .embeddings import (  # noqa: F401
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "dbgpt/rag/embedding/embeddings.py", line 6, in <module>
    import requests
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "requests/__init__.py", line 164, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "requests/api.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "requests/sessions.py", line 15, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 450, in exec_module
  File "requests/adapters.py", line 81, in <module>
FileNotFoundError: [Errno 2] No such file or directory

解决:

# 在datas中添加*.dist-info文件,基本解决
 ('/yourpath/site-packages/requests-2.32.3.dist-info/*','requests-2.32.3.dist-info/')

dist-info它为包的安装、管理和分发提供了标准化的元数据存储和管理方式,基本类似问题报错,只要你能找到对应的.dist-info文件夹,90%是这个导致的

大家还有什么问题和解决方案可以沟通一下!!!!!

ImportError: Could not import sentence_transformers python package. 在win11系统中,明明conda环境中已经安装了conda list中是存在这个库的,但还是报以下的错误。按照安装指示重新安装也无果。 阅读详情

相关推荐

pyinstaller打包Django项目+避坑指南

最近在搞Django的项目,看了挺多pyinstaller的打包教程,感觉都有遗漏跟错误,当然也可能是具体情况不一样导致的,以下内容是我根据自己的项目总结的,希望对大家有帮助

weixin_37934258的博客 6898

sentence_transformers安装成功,但是不能import

sentence_transformers安装成功,但是不能import

Ajdidfj的博客 3403

python 使用pyinstaller 打包scrapy中遇到的坑

打包scrapy果然好痛苦啊!!! 坑1: 不要用pycharm 下载PyInstaller包 ,不然在cmd里就算你设定好了环境变量,也是调用不了,最后我是用pip 删除再安装解决的! 坑2: 无论修改什么,还是会报出AttributeError: 'str' object has no attribute 'items'的问题,发现原来是setuptools比较老,方法是: 更新...

行者刘6 1650

sentence transformers安装

sentence-transformers安装

The_Ruthless的博客 3675

Pyinstaller加密打包遇到的坑

Pyinstaller加密打包的坑Pyinstaller加密打包遇到的坑 Pyinstaller加密打包遇到的坑 原来使用Anaconda3-2019.07-Windows-x86_64,Pyinstaller 3.4版本。升级到Anaconda3-2020.02-Windows-x86_64或者Python 3.7.7,使用Pyinstaller进行加密打包成EXE文件,可以成功打包。但是,运行...

u011195887的博客 3953

使用pyinstaller打包程序时踩过的坑

一直在学习新的东西,感觉当时学了!懂了!会了!但是过了就忘了!!!深刻反思后,觉得是没有总结的原因。刚好这段时间因为工作需要在学习pyqt,就把自己在使用pyinstaller对程序打包时遇到的一些问题及解决方法总结出来供大家参考,能力有限,若有不对的地方望指正。 pyinstaller参数 打包步骤 1.安装pyinstaller 2. 坑 坑一 坑二 ...

qq_42774567的博客 1万+

python打包系列1 - pyinstaller打包遇坑笔记

pyinstaller 指令实在太坑了

wu_zhiyuan的博客 1204

Python GUI开发之打包的那些坑(PyInstaller)

开发环境:win10+python3.6+pyqt5+pyinstaller3.4 前言 利用pyqt5开发了一个小工具,开发完成之后需要打包成EXE以供其他人方便地使用。这里的打包工具网上99%的人都推荐使用pyInstaller。也就一脚踏入了这个深坑。。。 断断续续用了两三次来做这个打包(在开发迭代过程中): 第一次摸索了一下,简单的依赖包的可以很方便的成功,太多依赖的就很容易失败,...

alwaysyxl的博客 4997

用pyinstaller打包python遇到的坑

最近写了一个小程序,用到了pandas,matplotlib模块,打包时出现各种问题,总结下走过的坑。 因为之前使用openpyxl写过一个更简单的程序,仅用来读写excel,打包的时候遇到过打包后文件太大,打包后文件200MB!可以参考下面的文章解决, Python打包exe文件方法汇总【4种】 在虚拟环境下打包,文件瘦身十分有效,仅10MB大小, 值得注意的是: pipenv shell激活...

chaoqichaoluoe的博客 1825

ImportError: Could not import faiss python package. Please install it with `pip install faiss` or `p

当pip install faiss失效的情况下,gpu配置,解决如下问题

weixin_45751925的博客 1375

ubuntu20.04安装UE4+Airsim环境

版本UE4.27+Airsim1.81

玖茸的博客 3380

pyinstaller打包遇到的一些坑

用Python的numpy,pandas,scipy,matplotlib和wxpython写了一个小软件,我用的环境是anaconda3(Python3.6),本来觉得打包后应该不大,打包的结果硬是达到了800多兆,很是无语,网上说要在虚拟环境中打包(Anaconda可以创建),这里有个坑就是你安装的pyinstaller也是在这个虚拟环境中才行,不然打包的结果还是你原来的环境。 (1)pyi...

HQ1356466973的博客 6685

NLP DAY1: 文本数据读取

txt 文本数据的读写CSV 及 Excel 文本数据的读写更多的 DataFrame 操作数据规模太大怎么办相信通过本次实验的学习,同学们可以游刃有余地面对各种数据文件了。在接下来的实验中,我们将开始真正地开启自然语言处理之旅,开始认识并熟悉一些常见的针对文本本身的预处理操作。

feifeikon的博客 1060

使用pyinstaller打包pytorch踩的那些坑

使用pyinstaller打包pytorch踩的那些坑问题1:单个文件打包还是文件夹打包?问题2:一起打包的数据文件找不到?问题3:GPU训练的模型要放到CPU环境跑? 花费了亿点时间,终于在自己的电脑上搞定了pyinstaller的安装并且让它成功打包了一些小程序之后,尝试着用它打包pytorch这样的复杂程序,结果遇到的问题远比想象中要多,于是记个笔记,也避免后来人踩坑。 问题1:单个文件打包还是文件夹打包? 用pyinstaller打包pytorch的感觉就是大,这文件真的大……已经尽力用from i

starvapour的博客 5057

手把手教你用STM32实现三相永磁同步电机FOC控制(附代码)

本文详细介绍了基于STM32的三相永磁同步电机(PMSM)FOC控制实现方法,涵盖硬件设计、软件架构、参数调试及完整代码解析。通过磁场定向控制(FOC)算法,实现高效精准的电机控制,适用于工业自动化、电动汽车等领域。文章还提供了硬件选型建议、电流采样方案对比及PID参数整定技巧,助力开发者快速掌握FOC控制技术。

weixin_29168675的博客 96

最新CobaltStrike4.8/CobaltStrike4.9、CS4.9/CS4.8、 Windows/Linux/Mac版下载

Cobalt Strike是一款基于java的渗透测试神器,常被业界人称为CS神器。自3.0以后已经不在使用Metasploit框架而作为一个独立的平台使用,分为客户端与服务端,服务端是一个,客户端可以有多个,非常适合团队协同作战,多个攻击者可以同时连接到一个团队服务器上,共享攻击资源与目标信息和sessions,可模拟APT做模拟对抗,进行内网渗透。 Cobalt Strike集成了端口转发、服务扫描,自动化溢出,多模式端口监听,win exe木马生成,win dll木马生成,java木马生成,

weixin_43167326的博客 7972

盘点在pyinstaller打包的时候遇到的一些坑

盘点在pyinstaller打包的时候遇到的一些坑 1、当遇到编码问题的时候要怎么解决 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dWbl6IDm-1606805468621)(https://cdn.jsdelivr.net/gh/13060923171/images@main/img/image-20201201090248717.png)] 在cmd窗口输入chcp 65001然后回车 这时编码问题就可以全部解决了 2、python maximum recursi

zyh960的博客 2万+

ChatGPT充值,银行卡被拒绝,图文教程

ChatGPT充值,银行卡被拒绝

weixin_46713695的博客 2万+

PyInstaller vs Nuitka/Cython 深度对比:性能优化、资源打包与避坑指南(附完整案例)

Nuitka默认不会自动打包资源文件,需手动指定;Cython需将资源处理逻辑编译进二进制模块,灵活性较低。使用PyInstaller打包PyQt/PySide等GUI程序时,图标、样式表()、配置文件等资源文件丢失,导致运行时崩溃或界面异常。获取PyQt打包完整项目。

燃灯工作室 2232

osgPython

osgPython是一组 Python 模块,为 OpenSceneGraph 的 C++ 库提供了完整的 Python 接口。这意味着你可以在 Python 中调用几乎所有的 OSG 功能,从创建简单的场景到复杂的渲染效果。核心优势开发速度快:Python 语法简洁,无需编译,快速迭代易于学习:比 C++ 更易上手,适合原型开发和教学生态丰富:可以结合 NumPy、Matplotlib 等科学计算库跨平台:与 OSG 一样支持 Windows、Linux、macOS性能考虑。

深之JohnChen的专栏 454

LangChain与LangGraph核心区别解析

LangChain与LangGraph是当前大语言模型(LLM)应用开发中两个紧密相关且极具影响力的开源框架。它们源于LangChain AI公司,设计哲学互补,旨在解决不同维度的LLM工程化问题,共同构成了构建复杂智能应用的强大工具集。

weixin_35774598的博客 1922

Pyinstaller打包的一些坑

Pyinstaller打包的坑 pyinstaller是python windows下打包的神器,但是使用过程中经常会碰到坑,以下是我碰到的坑。 1、打包体积太大 1.1在虚拟环境下搭建干净的环境 打开cmd 输入以下命令创建一个虚拟环境。 #建立虚拟环境 pipenv install #进入虚拟环境 pipenv shell #安装模块 pip install 你py文件里用到的模块 #打包的模...

weixin_46010338的博客 1258

核心组件大换血:Backbone与Neck魔改篇:YOLO26魔改Neck:引入BiFPN(双向特征金字塔),多尺度融合能力飙升

本文深入解析了YOLO26目标检测模型中Neck部分的优化策略,重点探讨了BiFPN(双向特征金字塔网络)的原理与实现。文章首先指出YOLO26原生FPN+PAN结构在多尺度特征融合上的局限性,特别是在小目标检测和边缘部署场景中的性能瓶颈。随后系统梳理了Neck网络的演进历程,从FPN、PANet到BiFPN和ASFF,详细对比了各架构的特点。核心部分展示了如何将BiFPN引入YOLO26,包括可学习权重融合、双向跨尺度连接等关键技术实现,并提供了PyTorch代码示例。本文为需要提升小目标检测性能或优化边

ZDQ58818的博客 246

Python使用pyinstaller打包踩坑合集

pyinstaller打包踩坑汇总

fengjian的博客 545

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

pyinstaller打包exe和踩过的坑

1、pycharm创建python虚拟环境(我目前创建的虚拟环境是基于python3.8的环境创建的)(一定创建虚拟环境,我开始用python38环境,打包删除都非常慢,耗时太久)2、项目根目录下生成requirements.txt3、项目下执行 pip install -r requirements.txt4、编辑如下配置文件5、datas下的任何一个目录里不能是空文件夹,不然打包不进去。

weixin_41989262的博客 1036

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

streamlit+wordcloud使用pyinstaller打包遇到的一些坑

streamlit应用结合wordcloud通过pyinstaller打包为exe的方法以及问题解决方案

qq_37461349的博客 1633

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

上一篇: pyinstaller打包项目后运行报错找不到依赖
下一篇: ONNXMiniLM_L6_V2找不到怎么办?来看看
努力的小豆子
博客等级 码龄6年 137粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的小豆子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值