报错原因查找

使用py2app打os 应用程序,测试模式程序运行无误,构建正式程序后运行出错:

查看控制台没找到具体报错原因,进入app所在路径

$ cd /Users/Rachel1900/myproject/code/code_to_be_packed/pic2txt

通过以下命令在terminnal中运行打包后的程序

./dist/pic2txt.app/Contents/MacOS/pic2txt

运行后报错如下:

ImportError: dlopen(/Users/Rachel1900/myproject/code/code_to_be_packed/pic2txt/dist/pic2txt_1.0.app/Contents/Resources/lib/python3.8/lib-dynload/PIL/_imaging.so, 2): Library not loaded: @loader_path/.dylibs/libxcb.1.1.0.dylibReferenced from: /Users/Rachel1900/myproject/code/code_to_be_packed/pic2txt/dist/pic2txt_1.0.app/Contents/Resources/lib/python3.8/lib-dynload/PIL/_imaging.soReason: image not found

dlopen():Library not loaded: @loader_path/.dylibs/libxcb.1.1.0.dylib 报错 Reason: image not found

问题解决

查询stackoverflow类似问题解决,找到类似问题:
Error: dlopen() Library not loaded Reason: image not found

报错原因:

加载一个库,而该库又需要加载另一个库时,则失去指定库及其直接路径的住向控制权,造成库加载报错。

Shared object location under OS X is sometimes tricky. When you directly call dlopen() you have the freedom of specifying an absolute path to the library, which works fine. However, if you load a library which in turn needs to load another (as appears to be your situation), you’ve lost control of specifying where the library lives with its direct path.

解决方案

更改所加载的动态库的路径

实现方法

  • 使用 otool -L ~.so找到出问题的库的具体地址
  • 使用install_name_tool命令更改库的地址
$ install_name_tool -change <old_path> <new_path> filename

原po报错为:

dlopen(/Users/ramesh/offline/build_icerec/lib/icecube/phys_services.so, 2): Library not loaded: /Users/ramesh/offline/build_icerec/lib/libphys-services.dylib
Referenced from:
/Users/ramesh/offline/build_icerec/lib/icecube/phys_services.so
Reason: image not found

原po出问题的库为 libphys-services.dylib

phys_services.so was statically linked against libphys-services.dylib.

因此给出的更改建议是:

install_name_tool -change /usr/lib/libphys-services.dylib @rpath/lib/libphys-services.dylib phys_services.so

old path: /usr/lib/libphys-services.dylib
new path :@rpath/lib/libphys-services.dylib phys_services.so.

自己出问题的库为:libxcb.1.1.0.dylib
使用install_name_tool -change oldpath newpath filename修改_imaging.so文件中的动态库调用路径

  • newpath:@executable_path/…/Frameworks
  • oldpath:@loader_path/.dylibs/libz.1.2.11.dylib(即报错详情)
install_name_tool -change @loader_path/.dylibs/libz.1.2.11.dylib @executable_path/../Frameworks/libxcb.1.1.0.dylib /Users/Rachel1900/myproject/code/code_to_be_packed/pic2txt/dist/pic2txt_1.0.app/Contents/Resources/lib/python3.8/lib-dynload/PIL/_imaging.so

问题解决

stackoverflow详细分析如下:

Shared object location under OS X is sometimes tricky. When you directly call dlopen() you have the freedom of specifying an absolute path to the library, which works fine. However, if you load a library which in turn needs to load another (as appears to be your situation), you’ve lost control of specifying where the library lives with its direct path.

There are environment variables that you could set before running your main program that tell the dynamic loader where to search for things. In general these are a bad idea (but you can read about them via the man dyld command on an OS X system).

When an OS X dynamic library is created, it’s given an install name; this name is embedded within the binary and can be viewed with the otool command. otool -L mach-o_binary will list the dynamic library references for the mach-o binary you provide the file name to; this can be a primary executable or a dylib, for example.

When a dynamic library is statically linked into another executable (either a primary executable or another dylib), the expected location of where that dylib being linked will be found is based on the location written into it (either at the time it was built, or changes that have been applied afterwards). In your case, it seems that phys_services.so was statically linked against libphys-services.dylib. So to start, run otool -L phys_services.so to find the exact expectation of where the dylib will be.
The install_name_tool command can be used to change the expected location of a library. It can be run against the dylib before it gets statically linked against (in which case you have nothing left to do), or it can be run against the executable that loads it in order to rewrite those expectations. The command pattern for this is install_name_tool -change <old_path> <new_path> So for example, if otool -L phys_services.so shows you /usr/lib/libphys-services.dylib and you want to move the expectation as you posed in your question, you would do that with install_name_tool -change /usr/lib/libphys-services.dylib @rpath/lib/libphys-services.dylib phys_services.so.
The dyld man page (man dyld) will tell you how @rpath is used, as well as other macros @loader_path and @executable_path.

简单来说:
OS X 下的共享对象位置有时比较棘手。当您直接调用 dlopen() 时,您可以自由地指定到库的绝对路径,该路径工作正常。但是,如果加载一个库,而该库又需要加载另一个库(这似乎是您的情况),则已失去指定库及其直接路径的住向控制权。
在运行主程序之前,可以设置一些环境变量,这些变量告诉动态加载器在搜索内容的地方。通常,这些都是一个坏主意(可以通过 OS X 系统上的 man dyld 命令阅读它们)。
当动态库静态链接到另一个可执行文件(主可执行文件或其他 dylib)时,将找到该 dylib 链接位置的预期位置,该位置将基于写入其中的位置(在生成时或之后应用的更改)。就你而言, phys_services. solibphys 服务. dylib 有静态联系。因此,首先,运行otool-L phys_services.所以找到对dylib将在哪里的确切期望。
install_name_tool命令可用于更改库的预期位置。它可以在 dylib 进行静态链接之前对 dylib 运行(在这种情况下,您没有什么可做的),也可以针对加载它以重写这些期望的可执行文件运行。此命令模式是install_name_tool - <old_path><new_path> 例如, 如果 otool - l phys_services.so 显示您 /usr/lib/libphys 服务.dylib,并且您想要移动您提出的问题时的期望,那么您将使用 install_name_tool - 更改 /usr/lib/libphys 服务.dylib @rpath/lib/libphys-services.dylib phys_services.so.

dyld man 页面 (man dyld) 将@rpath如何使用,以及其他宏@loader_path@executable_path。

其他参考:

stackoverflow.
dlopen: Library not loaded: @loader_path/.dylibs/libxcb.1.1.0.dylib
dlop():l

Linking to a dynamic library on a Mac with full path

What path does @loader_path resolve to?

how-to-fix-dyld-library-not-loaded-error-on-macos

其他可能原因

系统和动态库的二进制方法方法不一致

One possibility is that the binary type of the dylib doesn’t match the binary type of your program and you can check that with the “file” command. file /path/to/dylib and file /path/to/program.
Other than that I don’t know what the cause could be on macOS (though if you happen to be on iOS, sandboxing could be a likely cause

py2app-报错-ModuleNotFoundError: No module named ‘Image‘ dlopen():Library not loaded: @loader_path/.d相关推荐

  1. pandas写excel报错ModuleNotFoundError: No module named ‘xlwt‘

    pandas写excel报错ModuleNotFoundError: No module named 'xlwt' https://blog.csdn.net/weixin_36372879/arti ...

  2. 解决JupyterLab/JupyterNotebook安装pycherts后依旧报错报错 ModuleNotFoundError: No module named ‘pyecharts‘

    问题解析 即便使用pip list检查后,有pyecharts包,但是依旧无法导入pyecharts包,报错ModuleNotFoundError: No module named 'pyechart ...

  3. 运行django代码报错ModuleNotFoundError: No module named 'myapp'如何解决

    运行代码报错ModuleNotFoundError: No module named 'myapp'如何解决 您可以回顾一下之前是否使用过django核心模块中的User? from django.c ...

  4. Python使用pip安装报错ModuleNotFoundError: No module named ‘pip._internal.cli.main‘的解决方法

    Python使用pip安装报错ModuleNotFoundError: No module named 'pip._internal.cli.main'的解决方法   大家好,我叫亓官劼(qí guā ...

  5. Python使用pip安装报错ModuleNotFoundError: No module named ‘pkg_resources‘的解决方法

    Python使用pip安装报错ModuleNotFoundError: No module named 'pkg_resources'的解决方法   大家好,我叫亓官劼(qí guān jié ),在 ...

  6. 报错ModuleNotFoundError: No module named ‘easydict‘

    from easydict import EasyDict as edict 报错ModuleNotFoundError: No module named 'easydict' 之后使用:pip in ...

  7. pip报错ModuleNotFoundError: No module named ‘dataclasses’

    pip报错ModuleNotFoundError: No module named 'dataclasses'解决 问题描述 使用pip无论输入何种指令都会出现如下报错,见下截图 初步的解决思路是重装 ...

  8. pip报错ModuleNotFoundError: No module named ‘dataclasses‘解决

    pip报错ModuleNotFoundError: No module named 'dataclasses'解决 问题描述 使用pip无论输入何种指令都会出现如下报错,见下截图 初步的解决思路是重装 ...

  9. 解决Ubuntu报错ModuleNotFoundError: No module named ‘pip‘

    Ubuntu报错ModuleNotFoundError: No module named 'pip' 解决方法: sudo apt install python3-pip

最新文章

  1. Revit和Unreal Engine真实的建筑可视化视频教程
  2. IDEA 显示类结构图
  3. 每日英语:Relationship Repair: 10 Tips for Thinking Like a Therapist
  4. C/C++语言void及void指针深层探索 .
  5. vscode 将本地项目上传到github、从github克隆项目以及删除github上的某个文件夹
  6. 目前我们再用的即时通讯软件
  7. iOS-高仿支付宝手势解锁(九宫格)
  8. 如何进行cad地理配准_【教程】自带高度建筑轮廓如何制作分色图
  9. 北京语言大学计算机科学与技术研究生好考吗,北京语言大学计算机科学与技术专业研究生培养方案...
  10. linux超过cpu负载重启脚本,linux下Web服务器CPU负载超过阀值自动重启脚本
  11. MYSQL5.6创建表报错 [ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
  12. Android NDK开发之 NEON使用介绍
  13. paip.环境设置 mybatis ibatis cfg 环境设置
  14. 使用Selenium启动火狐浏览器
  15. 编程之道 The Tao Of Programming
  16. c语言余数求和,C语言实现两数相加2018-09-23(示例代码)
  17. php 测试网站打开速度,利用JS测试目标网站的打开响应速度_javascript技巧
  18. 对外汉语偏误语料库_对外汉语偏误
  19. 转:西部数据NAS设备hack
  20. c++软件开发面试旋极面试题_北京旋极信息技术股份有限公司2015招聘

热门文章

  1. 使用跨平台的visual studio code 进行python 开发
  2. 【保险杂谈】聊聊那些让人眼红的“分红保险”
  3. 一些不错的 SCI 科研工具
  4. 自己制作字体的试验(自制字体使用FontForge等)
  5. Android Studio 连接真机测试
  6. 极力推荐一个简单好用的C++JSON库
  7. php程序员秃顶问题,程序员真的容易秃头吗?这两者之间真的有必然的联系吗?...
  8. 计算机教室如何防火,2020校园防火安全小知识_消防安全小知识顺口溜
  9. 计算机教室电气设计规范,5.2 低压配电系统 - 教育建筑电气设计规范 JGJ/T310-2013 - 消防规范大全 - 消防资源网!...
  10. 下次遇到需要搭建公司秒杀架构,打开这套架构直接用...,细节都考虑到了!...