首页 > 解决方案 > 使用 py2app 编译时如何修复未加载的库:@rpath/libssl.1.1.dylib?

问题描述

环境:

Mac OS X Catalina 10.15.6 Python 8

嗨,我尝试用 py2app 编译我的 python 代码。这是我的 setup.py:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['MyApp.py']
APP_NAME = "MyApp"
DATA_FILES = [ 'necessary_files/create_db.sql',
                    'necessary_files/fra.traineddata',
                    'necessary_files/ui.txt',
                    'MyApp_Install.sh',
                    'necessary_files/assets',
                    'necessary_files/cgi',
                    'necessary_files/selenium',
                    'ui/']
OPTIONS = {
    'iconfile': 'MyApp_icon.icns',
    'packages': ['requests', 'selenium'],
    'plist': {
        'CFBundleName': APP_NAME,
        'CFBundleDisplayName': APP_NAME,
        'CFBundleGetInfoString': "Marketing Bot",
        'CFBundleIdentifier': "com.cff.MyApp",
        'CFBundleVersion': "0.0.2",
        'CFBundleShortVersionString': "0.0.2",
        'NSHumanReadableCopyright': u"Copyright © 2020, CFF, All Rights Reserved"}
        }

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

编译完成后,我在终端中使用此命令运行我的应用程序以查看错误并得到以下信息:

/Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/MacOS/MyApp ; exit;
(base) gauthierbtz@MacBook-de-Gauthier ~ % /Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/MacOS/MyApp ; exit;
Traceback (most recent call last):
  File "/Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/__boot__.py", line 115, in <module>
    _run()
  File "/Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/__boot__.py", line 84, in _run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/MyApp.py", line 29, in <module>
    import mymodules
  File "<frozen zipimport>", line 259, in load_module
  File "mymodules.pyc", line 5, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "ssl.pyc", line 98, in <module>
ImportError: dlopen(/Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/lib/python3.8/lib-dynload/_ssl.so, 2): Library not loaded: @rpath/libssl.1.1.dylib
  Referenced from: /Users/gauthierbtz/Dropbox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/lib/python3.8/lib-dynload/_ssl.so
  Reason: image not found
2020-09-12 22:15:58.769 MyApp[81463:1290389] MyApp Error

所以我在谷歌搜索解决方案并尝试了一些东西。

我使用命令“brew reinstall openssl”重新安装 openssl

我在我的 .zshrc 文件中添加了这个:

export PATH="/usr/local/opt/openssl\@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl\@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl\@1.1/include"

我重新启动我的终端。

我在终端中输入了这些行:

export LDFLAGS="-L/usr/local/opt/openssl\@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl\@1.1/include"

而且我仍然收到相同的错误消息。我不知道还能做什么。

如果有帮助,我在这里上传了编译日志。我没有看到任何奇怪的东西: https ://github.com/gauthierbuttez/public/blob/master/logs_py2app.txt

有人能帮助我吗?

标签: python-3.xmacospy2app

解决方案


我偶然发现了在构建可执行文件的链接器阶段可以链接共享库但在运行时找不到的相同问题。就我而言,解决方案是告诉 dyld 在我运行程序时在正确的路径中查找共享库:

DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/PATH_TO/YOUR_/DYLIB_FILE Run_me

我希望这也对你有用。


推荐阅读