pyinstaller打包项目时常见错误汇总分析?

2026-06-10 20:067阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1012个文字,预计阅读时间需要5分钟。

pyinstaller打包项目时常见错误汇总分析?

在使用pyzbar模块进行二维码识别时,遇到1.1版本安装问题。解决步骤如下:

1. 确认已正确安装pyzbar模块。

2.尝试重新安装pyzbar,使用以下命令:

pip install pyzbar==1.1

3.安装完成后,启动项目,若出现`FileNotFoundError: Could not find module '你的路径\Python\Python38\site-packages'`错误,请检查以下原因:

- Python环境路径设置不正确。 - 项目运行时未正确引用pyzbar模块。

解决方法:

1.确保Python环境路径正确。

2.检查项目代码中pyzbar模块的引用路径是否正确。

一、二维码识别模块 pyzbar报错

1.1 模块安装报错


项目识别二维码需要安装pyzbar,安装完,启动项目出现如下报错!
​​​FileNotFoundError: Could not find module '你的路径\Python\Python38\site-packages\pyzbar\libzbar-64.dll' (or one of its dependencies). Try using the full path with constructor syntax​​

解决方法:

  • 没事,这个坑我已经踩过。这个报错的原因是没有安装​​Visual C++​​的依赖库
  • 下载地址:​​Visual C++ Redistributable Packages for Visual Studio 2013​​
  • 进入之后,拉到下面可以看到下载的按钮,下载完之后安装即可!:

1.2 pyinstaller打包后Failed to load dynlib/dll 'libiconv.dll'

项目在没打包前运行没问题,识别正常,打包后就有以下报错,这是因为该模块的dll加载失败造成的

Traceback (most recent call last):
File "pyzbar\zbar_library.py", line 58, in load
File "pyzbar\zbar_library.py", line 50, in load_objects
File "pyzbar\zbar_library.py", line 51, in
File "ctypes\__init__.py", line 447, in LoadLibrary
File "PyInstaller\loader\pyimod04_ctypes.py", line 56, in __init__
pyimod04_ctypes.PyInstallerImportError: Failed to load dynlib/dll 'libiconv.dll'. Most probably this dynlib/dll was not found when the application was frozen.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PyInstaller\loader\pyimod04_ctypes.py", line 54, in __init__
File "ctypes\__init__.py", line 369, in __init__
FileNotFoundError: Could not find module 'D:\代码\weebot\main\pyzbar\libiconv.dll'. Try using the full path with constructor syntax.

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

Traceback (most recent call last):
File "main.py", line 9, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "bot_core\wechat.py", line 15, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyzbar\pyzbar.py", line 7, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyzbar\wrapper.py", line 139, in
File "pyzbar\wrapper.py", line 136, in zbar_function
File "pyzbar\wrapper.py", line 115, in load_libzbar
File "pyzbar\zbar_library.py", line 60, in load
File "pyzbar\zbar_library.py", line 50, in load_objects
File "pyzbar\zbar_library.py", line 51, in
File "ctypes\__init__.py", line 447, in LoadLibrary
File "PyInstaller\loader\pyimod04_ctypes.py", line 56, in __init__
pyimod04_ctypes.PyInstallerImportError: Failed to load dynlib/dll 'D:\\代码\\weebot\\main\\pyzbar\\libiconv.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[3632] Failed to execute script 'main' due to unhandled exception!

解决方法:

第一种方法:在自己的虚拟环境中找到该模块的dll,手动复制粘贴到打包后目录即可:

第二种方法:修改spec文件的时候设置好导入位置,打包时会自动识别

二、某些模块无法用pipenv安装,或者安装后可以使用,打包后出错

详见以下文章第五步:

pyinstaller打包完整python项目 pyinstaller如何给打包后的文件添加文件版本信息

三、打包后无法正常运行,闪退

我遇到这个情况,不打包运行的好好的,打包后一运行就闪退,

不要用双击模式运行,可以用cmd或者powershell运行exe,这样闪退后打印出报错信息

报错缺少模块,这种情况很可能是没有在虚拟环境内部进行打包,详见以下文章描述,严格执行打包流程再来一次可能就好了

pyinstaller打包完整python项目 pyinstaller如何给打包后的文件添加文件版本信息

四pipenv graph 执行报错 IndexError: list index out of range pipenv安装模块出错

pyinstaller打包项目时常见错误汇总分析?

本文共计1012个文字,预计阅读时间需要5分钟。

pyinstaller打包项目时常见错误汇总分析?

在使用pyzbar模块进行二维码识别时,遇到1.1版本安装问题。解决步骤如下:

1. 确认已正确安装pyzbar模块。

2.尝试重新安装pyzbar,使用以下命令:

pip install pyzbar==1.1

3.安装完成后,启动项目,若出现`FileNotFoundError: Could not find module '你的路径\Python\Python38\site-packages'`错误,请检查以下原因:

- Python环境路径设置不正确。 - 项目运行时未正确引用pyzbar模块。

解决方法:

1.确保Python环境路径正确。

2.检查项目代码中pyzbar模块的引用路径是否正确。

一、二维码识别模块 pyzbar报错

1.1 模块安装报错


项目识别二维码需要安装pyzbar,安装完,启动项目出现如下报错!
​​​FileNotFoundError: Could not find module '你的路径\Python\Python38\site-packages\pyzbar\libzbar-64.dll' (or one of its dependencies). Try using the full path with constructor syntax​​

解决方法:

  • 没事,这个坑我已经踩过。这个报错的原因是没有安装​​Visual C++​​的依赖库
  • 下载地址:​​Visual C++ Redistributable Packages for Visual Studio 2013​​
  • 进入之后,拉到下面可以看到下载的按钮,下载完之后安装即可!:

1.2 pyinstaller打包后Failed to load dynlib/dll 'libiconv.dll'

项目在没打包前运行没问题,识别正常,打包后就有以下报错,这是因为该模块的dll加载失败造成的

Traceback (most recent call last):
File "pyzbar\zbar_library.py", line 58, in load
File "pyzbar\zbar_library.py", line 50, in load_objects
File "pyzbar\zbar_library.py", line 51, in
File "ctypes\__init__.py", line 447, in LoadLibrary
File "PyInstaller\loader\pyimod04_ctypes.py", line 56, in __init__
pyimod04_ctypes.PyInstallerImportError: Failed to load dynlib/dll 'libiconv.dll'. Most probably this dynlib/dll was not found when the application was frozen.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PyInstaller\loader\pyimod04_ctypes.py", line 54, in __init__
File "ctypes\__init__.py", line 369, in __init__
FileNotFoundError: Could not find module 'D:\代码\weebot\main\pyzbar\libiconv.dll'. Try using the full path with constructor syntax.

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

Traceback (most recent call last):
File "main.py", line 9, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "bot_core\wechat.py", line 15, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyzbar\pyzbar.py", line 7, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyzbar\wrapper.py", line 139, in
File "pyzbar\wrapper.py", line 136, in zbar_function
File "pyzbar\wrapper.py", line 115, in load_libzbar
File "pyzbar\zbar_library.py", line 60, in load
File "pyzbar\zbar_library.py", line 50, in load_objects
File "pyzbar\zbar_library.py", line 51, in
File "ctypes\__init__.py", line 447, in LoadLibrary
File "PyInstaller\loader\pyimod04_ctypes.py", line 56, in __init__
pyimod04_ctypes.PyInstallerImportError: Failed to load dynlib/dll 'D:\\代码\\weebot\\main\\pyzbar\\libiconv.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[3632] Failed to execute script 'main' due to unhandled exception!

解决方法:

第一种方法:在自己的虚拟环境中找到该模块的dll,手动复制粘贴到打包后目录即可:

第二种方法:修改spec文件的时候设置好导入位置,打包时会自动识别

二、某些模块无法用pipenv安装,或者安装后可以使用,打包后出错

详见以下文章第五步:

pyinstaller打包完整python项目 pyinstaller如何给打包后的文件添加文件版本信息

三、打包后无法正常运行,闪退

我遇到这个情况,不打包运行的好好的,打包后一运行就闪退,

不要用双击模式运行,可以用cmd或者powershell运行exe,这样闪退后打印出报错信息

报错缺少模块,这种情况很可能是没有在虚拟环境内部进行打包,详见以下文章描述,严格执行打包流程再来一次可能就好了

pyinstaller打包完整python项目 pyinstaller如何给打包后的文件添加文件版本信息

四pipenv graph 执行报错 IndexError: list index out of range pipenv安装模块出错

pyinstaller打包项目时常见错误汇总分析?