【问题标题】:Python crashing on MacOS 10.15 Beta (19A582a) with "/usr/lib/libcrypto.dylib"Python 在 MacOS 10.15 Beta (19A582a) 上使用“/usr/lib/libcrypto.dylib”崩溃
【发布时间】:2019-10-07 15:37:12
【问题描述】:

我使用新的 macOS Catalina 运行了我的 Django 项目,并且运行良好。
我安装了 oh_my_zsh 然后我尝试运行相同的项目,它因以下错误而崩溃。我卸载了 oh_my_zsh 并再次尝试,但没有成功。

Path:                  /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.7.4 (3.7.4)
Code Type:             X86-64 (Native)
Parent Process:        Python [7526]
Responsible:           Terminal [7510]
User ID:               501

Date/Time:             2019-10-07 20:59:20.675 +0530
OS Version:            Mac OS X 10.15 (19A582a)
Report Version:        12
Anonymous UUID:        CB7F20F6-96C0-4F63-9EC5-AFF3E0989687


Time Awake Since Boot: 3000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
/usr/lib/libcrypto.dylib
abort() called
Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.

【问题讨论】:

  • 如果您在 virtualenv 中:对我来说,对 venv 进行了(完全)重置(删除它并使用所有依赖项等重新创建它)

标签: python oh-my-zsh libcrypto macos-catalina


【解决方案1】:

我刚遇到同样的问题,手动链接东西有点不舒服。

我可以简单地解决问题

  1. 通过自制软件安装 openssl:
    brew install openssl
    
  2. 通过 DYLD_LIBRARY_PATH 从 openssl 指向动态库:
    export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH
    

我刚刚将该行添加到我的 .zshrc 中。

编辑:根据this questionDYLD_FALLBACK_LIBRARY_PATH 的使用可能比DYLD_LIBRARY_PATH 更可取。

编辑 2:正如下面评论中提到的,this 可能应该是公认的答案。只需重新安装cryptography 软件包即可。

【讨论】:

  • 这在命令行中也适用于我,但它不适用于脚本。会不会少了什么?
  • 如何运行脚本?如果您没有从 shell 运行脚本(使用调整后的环境变量),您可能需要在 /etc/profile.xml 中的某处设置该变量。我认为这个环境变量并不是真的打算用于“生产”脚本......
  • 可以确认export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/opt/openssl/lib 工作正常。感谢您的提示!
  • 这非常适合让事情正常进行,但并不能完全解决问题。我有一些需要使用 Python 的 crontab 作业,我不想确保它们都有这个环境设置。我喜欢下面@Andrei 的解决方案。它为最新的 openssl 库设置了符号链接,以便将来升级时链接也将如此。 stackoverflow.com/a/58596931/142318
  • 每个人都应该在此之前尝试下面的@tonyStarks 答案,它可能只是一个简单的卸载和重新安装
【解决方案2】:

对我来说,重新安装 Python 的加密包就足够了。

pip uninstall cryptography
pip install cryptography

【讨论】:

  • 它对我有用。在我的情况下,将 virtualenv 更新到最新版本后未执行 ansible。
  • 成功了!谢谢!对我来说,是pip uninstall cryptography 而不是remove
  • 这也为我修复了它。谢谢!
  • 太棒了,它适用于 MacOS 10.15.4。非常感谢!
  • 在 MacOS 10.15.7 上工作。谢谢!
【解决方案3】:

警告:我不是安全专家,此解决方案与加密库相混淆!

我不认为您的问题源于 zsh 或 oh-my-zsh。我的最佳猜测:MacOS 10.15 安装的一些加密库与 Homebrew 的 python3 安装不兼容。

这就是为我解决问题的方法

# Install openssl via homebrew.
# Note: According to homebrew, "openssl is keg-only, which means it was
# not symlinked into /usr/local, because Apple has deprecated use of
# OpenSSL in favor of its own TLS and crypto libraries."
brew install openssl
# Symlink those versions into /usr/local/lib, which gets Python to dynamically
# link against those instead of the version in /usr/lib/.
# Got the idea from https://forums.developer.apple.com/thread/119429
cd /usr/local/lib
sudo ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libssl.1.0.0.dylib libssl.dylib
sudo ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libcrypto.1.0.0.dylib libcrypto.dylib

我的上下文情况:

  • 最近升级到 MacOS 10.15
  • 我使用通过自制软件安装的 python/pip:brew install python
  • pip3SIGABRT 失败

系统错误报告的标题:

Process:               Python [52429]
Path:                  /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.7.4 (3.7.4)
Code Type:             X86-64 (Native)
Parent Process:        zsh [43309]
Responsible:           iTerm2 [2316]
User ID:               501

Date/Time:             2019-10-09 09:52:18.148 -0700
OS Version:            Mac OS X 10.15 (19A583)
Report Version:        12
Bridge OS Version:     4.0 (17P572)
Anonymous UUID:        

Sleep/Wake UUID:       

Time Awake Since Boot: 9900 seconds
Time Since Wake:       7300 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
/usr/lib/libcrypto.dylib
abort() called
Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.

【讨论】:

    【解决方案4】:

    我更喜欢@bixel、@Juro Oravec 和@honkaboy 的组合答案:

    brew install openssl
    cd /usr/local/lib
    sudo ln -s /usr/local/opt/openssl/lib/libssl.dylib libssl.dylib
    sudo ln -s /usr/local/opt/openssl/lib/libcrypto.dylib libcrypto.dylib
    

    这样,至少在理论上,更新 openssl 时,dylib 将始终指向最新版本。 /usr/local/opt/openssl 实际上是指向/usr/local/Cellar/openssl/Cellar/openssl/1.0.2t 的链接(brew 安装的openssl 版本)。

    问题发生的原因其实是brew解释的:

    openssl 仅限于小桶,这意味着它没有符号链接到 /usr/local, 因为 Apple 已弃用 OpenSSL,转而使用自己的 TLS 和加密库。

    尝试运行brew link openssl:

    警告:拒绝链接 macOS 提供的软件:openssl 如果需要 在您的 PATH 运行中首先使用 openssl:echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

    要让编译器找到 openssl,您可能需要设置:export LDFLAGS="-L/usr/local/opt/openssl/lib" 导出 CPPFLAGS="-I/usr/local/opt/openssl/include"

    要让 pkg-config 找到 openssl,您可能需要设置:export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

    所以,基本上你需要手动链接它们。

    【讨论】:

      【解决方案5】:

      r.xuan from this Apple Dev thread 确定了解决该错误的步骤 Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI. 通过将 /usr/local/lib 中的 libssl.dyliblibcrypto.dylib 链接替换为 Homebrew 安装的 openssl 中的库链接。

      步骤如下:

      获取新鲜的库

      1)brew update && brew upgrade && brew install openssl

      2)cd /usr/local/Cellar/openssl/1.0.2t/lib

      3)sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib/

      备份旧的

      4) cd /usr/local/lib

      5)mv libssl.dylib libssl_bak.dylib

      6)mv libcrypto.dylib libcrypto_bak.dylib

      创建新链接

      7) sudo ln -s libssl.1.0.0.dylib libssl.dylib

      8) sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib

      【讨论】:

      • 这在 Catalina 10.15.4 上对我有用,但我有 /usr/local/Cellar/openssl@1.1 并使用了等效文件。使用 x.1.0.0.dylib 文件,pip3 仍然崩溃。
      【解决方案6】:

      我在ansible 上看到了类似的问题。罪魁祸首是asn1crypto,问题一直是already fixed

      我的解决方案是手动删除它并使用pip 重新安装它:

      1. rm -r /usr/local/lib/python2.7/site-packages/asn1crypto*。这让pip 可以毫无问题地工作。
      2. pip install asn1crypto,其中安装了1.2.0
        Found existing installation: asn1crypto 0.24.0
          Uninstalling asn1crypto-0.24.0:
            Successfully uninstalled asn1crypto-0.24.0
      Successfully installed asn1crypto-1.2.0
      

      注意:您可以通过在详细模式下运行 python 来检查 asn1crypto 是否是罪魁祸首,例如python -v $(which ansible)。就我而言,它在执行一些 asn1crypto 相关导入时崩溃了:

      # /usr/local/lib/python2.7/site-packages/asn1crypto/_perf/_big_num_ctypes.pyc matches /usr/local/lib/python2.7/site-packages/asn1crypto/_perf/_big_num_ctypes.py
      import asn1crypto._perf._big_num_ctypes # precompiled from /usr/local/lib/python2.7/site-packages/asn1crypto/_perf/_big_num_ctypes.pyc
      [1]    59247 abort      python -v $(which ansible)
      

      相关:https://github.com/Homebrew/homebrew-core/issues/44996

      【讨论】:

      • 这对我有用。我使用的是根网格,它使用 ansible。我做了答案中列出的rm -r 命令,然后我在trellis/.trellis/virtualenv 目录中删除了我的python 环境,然后使用trellis-cli 我做了trellis init,它重新创建了一个python 环境并使用pip 安装了依赖项。
      【解决方案7】:

      一定是用到了一些依赖,比如cryptography

      解决方案:

      cd your-site-packages-path/
      vim ./asn1crypto/_int.py
      

      找到这一行;删除它,一切正常

      # from ._perf._big_num_ctypes import libcrypto
      

      这是我的问题

      Process:               Python [85179]
      Path:                  /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
      Identifier:            Python
      Version:               3.7.4 (3.7.4)
      Code Type:             X86-64 (Native)
      Parent Process:        ??? [85161]
      Responsible:           iTerm2 [11711]
      User ID:               501
      
      Date/Time:             2019-10-07 23:00:25.143 +0800
      OS Version:            Mac OS X 10.15 (19A582a)
      Report Version:        12
      Bridge OS Version:     3.0 (14Y906)
      Anonymous UUID:        32C73ADD-1291-FA0E-DC02-48D539674325
      
      
      Time Awake Since Boot: 42000 seconds
      
      System Integrity Protection: enabled
      
      Crashed Thread:        0  Dispatch queue: com.apple.main-thread
      
      Exception Type:        EXC_CRASH (SIGABRT)
      Exception Codes:       0x0000000000000000, 0x0000000000000000
      Exception Note:        EXC_CORPSE_NOTIFY
      
      Application Specific Information:
      /usr/lib/libcrypto.dylib
      abort() called
      Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.
      

      【讨论】:

        【解决方案8】:

        试试:

        python3 -m pip install oscrypto
        

        为我工作!

        【讨论】:

          【解决方案9】:

          恐怕这些答案都不是我能接受的。因为这些答案并没有解决问题。他们中的一些人是幸运的,或者误解了,甚至是错误的。所以我将提供我自己的解决方案并详细解释问题。

          dylib 加载无效。客户端不应加载未版本化的 libcrypto dylib,因为它没有稳定的 ABI。

          根本原因本身就很清楚。您的 Python 正试图打开(由 dlopen)一个名为 libcrypto 的未版本化 OpenSSL 共享库。自 Catalina 以来,出于安全原因,Apple 不允许任何人使用它。所以解决方案很简单。只是使用版本控制 OpenSSL。

          我编写了一个名为openlib.py 的python 脚本来重现该问题。

          import sys
          from ctypes.util import find_library
          from ctypes import CDLL
          
          name = sys.argv[1]
          path = find_library(name)
          print(f"path: {path}")
          lib = CDLL(path)
          

          我这里使用系统 Python 进行演示

          $ sw_vers
          ProductName:    Mac OS X
          ProductVersion: 10.15.7
          BuildVersion:   19H15
          $ /usr/bin/python3 --version
          Python 3.8.2
          $ ls -al /usr/lib/ | grep 'libcrypto\|libssl'
          .rwxr-xr-x 1.1M root 22 Sep  8:29 libcrypto.0.9.7.dylib
          .rwxr-xr-x 1.4M root 22 Sep  8:29 libcrypto.0.9.8.dylib
          .rwxr-xr-x 1.5M root 22 Sep  8:29 libcrypto.35.dylib
          .rwxr-xr-x 1.5M root 22 Sep  8:29 libcrypto.41.dylib
          .rwxr-xr-x 1.5M root 22 Sep  8:29 libcrypto.42.dylib
          .rwxr-xr-x 1.5M root 22 Sep  8:29 libcrypto.44.dylib
          .rwxr-xr-x  32k root 22 Sep  8:29 libcrypto.dylib
          .rwxr-xr-x 212k root 22 Sep  8:29 libssl.0.9.7.dylib
          .rwxr-xr-x 335k root 22 Sep  8:30 libssl.0.9.8.dylib
          .rwxr-xr-x 330k root 22 Sep  8:28 libssl.35.dylib
          .rwxr-xr-x 313k root 22 Sep  8:29 libssl.43.dylib
          .rwxr-xr-x 300k root 22 Sep  8:29 libssl.44.dylib
          .rwxr-xr-x 294k root 22 Sep  8:29 libssl.46.dylib
          .rwxr-xr-x  32k root 22 Sep  8:29 libssl.dylib
          $ /usr/bin/python3 openlib.py libcrypto
          path: /usr/lib/libcrypto.dylib
          Abort trap: 6
          $ /usr/bin/python3 openlib.py libcrypto.35
          path: /usr/lib/libcrypto.35.dylib
          $ /usr/bin/python3 openlib.py libcrypto.44
          path: /usr/lib/libcrypto.44.dylib
          

          如您所见。 Python 已崩溃,参数 libcrypto 如下诊断报告所示。看起来很相似,对吧?宾果游戏!

          Process:               Python [97291]
          Path:                  /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
          Identifier:            Python
          Version:               3.8.2 (3.8.2)
          Build Info:            python3-73040006000000~117
          Code Type:             X86-64 (Native)
          Parent Process:        bash [84388]
          Responsible:           iTerm2 [7705]
          User ID:               501
          
          Date/Time:             2020-12-26 00:28:00.281 +0800
          OS Version:            Mac OS X 10.15.7 (19H15)
          Report Version:        12
          Anonymous UUID:        1C43F3DB-1783-4B94-B663-7F7E8D331B56
          
          
          Time Awake Since Boot: 53000 seconds
          
          System Integrity Protection: enabled
          
          Crashed Thread:        0  Dispatch queue: com.apple.main-thread
          
          Exception Type:        EXC_CRASH (SIGABRT)
          Exception Codes:       0x0000000000000000, 0x0000000000000000
          Exception Note:        EXC_CORPSE_NOTIFY
          
          Application Specific Information:
          /usr/lib/libcrypto.dylib
          abort() called
          Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.
          
          Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
          0   libsystem_kernel.dylib          0x00007fff69bba33a __pthread_kill + 10
          1   libsystem_pthread.dylib         0x00007fff69c76e60 pthread_kill + 430
          2   libsystem_c.dylib               0x00007fff69b41808 abort + 120
          3   libcrypto.dylib                 0x00007fff6766b7e4 __report_load + 415
          

          基于您的 Python /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python 的路径。显然,您的 Python 是由 Homebrew 安装的。我相信 Homebrew Python 3 一直是linked with keg-only OpenSSL。所以肯定是一些包使用了未版本化的 OpenSSL。查看文件ctypes/macholib/dyld.py2。它按指定顺序搜索以下目录中的任何库:

          DEFAULT_LIBRARY_FALLBACK = [
              os.path.expanduser("~/lib"),
              "/usr/local/lib",
              "/lib",
              "/usr/lib",
          ]
          
          $ /usr/bin/python3
          Python 3.8.2 (default, Nov  4 2020, 21:23:28)
          [Clang 12.0.0 (clang-1200.0.32.28)] on darwin
          Type "help", "copyright", "credits" or "license" for more information.
          >>> from ctypes.util import find_library
          >>> find_library('libcrypto')
          '/usr/lib/libcrypto.dylib'
          >>>
          

          因此,简单的解决方法是将版本控制 OpenSSL 链接到主目录中的库路径。

          $ pwd
          /Users/gasolwu
          $ ln -s /usr/lib/libcrypto.44.dylib $HOME/lib/libcrypto.dylib
          $ $ ls ~/lib
          libcrypto.dylib
          

          之后。通过运行提供的脚本 openlib.py 来测试打开 OpenSSL。它成功返回库路径而不会崩溃。

          $ /usr/bin/python3 openlib.py libcrypto
          path: /Users/gasolwu/lib/libcrypto.dylib
          

          我也使用Homebrew Python 3。所以我几天前修复了它并发送了a pull request。如果你已经升级到最新版本的 Python 并且如果 PR 已经合并并且瓶子已经构建和发布。只需使用brew reinstall python@3.9 运行命令将是解决问题的最简单方法。

          不要通过禁用 SIP 并使用 sudo 覆盖您的系统 OpenSSL 来破坏您的系统。

          不要安装浪费磁盘空间的重复库。无需在任何位置安装另一个 OpenSSL。

          不要使用环境变量DYLD_LIBRARY_PATH,如下所示。如果你不将这一行添加到你的shell配置中,你必须每次都声明。如果这样做,它将影响您机器上的每个程序。

          export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH
          

          最后。 如果您通过更新 python 依赖项解决了问题。你可能很幸运。一些软件包通过寻找版本控制 OpenSSL 解决了这个问题。但很多不是。

          【讨论】:

          • 精彩的点,并已被大量考虑。我真的很感激这个建议。另外,加索尔,我建议将“不要”行加粗,因为对于正在寻找快速解决方案的人来说,它看起来只是一大块文本。幸运的是,“不要”引起了我的注意,但其他人可能就没那么幸运了。
          • @developer01 我做到了,谢谢你的评论。
          • 不客气!!
          【解决方案10】:

          如果您使用 DevMate 的 Kevlar,请升级到 4.3.1,其中“修复了由 libcrypto.dylib 版本导致的 macOS Catalina 崩溃”。

          【讨论】:

            【解决方案11】:

            看起来这是 Homebrew 问题。我做了brew reinstall python3,它成功了。

            【讨论】:

              【解决方案12】:

              按照上面提到的答案,想链接libssl.dylib文件,但发现没有如下位置:

              /usr/local/Cellar/openssl/1.0.2t/lib/
              

              但是,@bixel 接受的答案在以下位置找到了文件

              /usr/local/opt/openssl/lib
              

              它对我有用。

              【讨论】:

                【解决方案13】:

                我在使用ctypes.cdllPython 3.7 打开/usr/lib/libcrypto.dylib 时遇到了同样的问题。但是dylib 可以用Python 2.7 打开。

                我用brew install安装了最新的openssl,然后按照他们上面的建议设置环境变量并创建链接,没有发生任何好事。

                经过几个小时的挖掘,我找到了解决方法。

                我在/usr中找到了一些libcrypto.X.dylib,如下所示,

                /usr/lib/libcrypto.dylib
                /usr/lib/libcrypto.0.9.7.dylib
                /usr/lib/libcrypto.0.9.8.dylib
                /usr/lib/libcrypto.35.dylib
                /usr/lib/libcrypto.41.dylib
                /usr/lib/libcrypto.42.dylib
                /usr/lib/libcrypto.44.dylib
                
                /usr/local/opt/openssl/lib/libcrypto.1.1.dylib
                /usr/local/opt/openssl/lib/libcrypto.dylib
                

                首先,我用followed替换了/usr/lib中的那个。

                os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/usr/local/opt/openssl/lib'
                

                可以加载但缺少一些api,

                AttributeError: dlsym(0x..., ECDH_OpenSSL): symbol not found
                

                我在脚本路径中为/usr/lib/libcrypto.X.dylib 创建了一个链接。

                ln -s /usr/lib/libcrypto.X.dylib lib/libcrypto.dylib
                

                然后添加DYLD_FALLBACK_LIBRARY_PATH的路径

                os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = 'lib' # It should be a absolute path
                

                终于成功了。

                【讨论】:

                  【解决方案14】:

                  使用以下步骤解决:

                  • brew update && brew upgrade && brew reinstall openssl
                  • cd /usr/local/Cellar/openssl@1.1/1.1.1g/lib
                  • sudo cp libssl.1.1.1.dylib libcrypto.1.1.1.dylib /usr/local/lib/
                  • sudo ln -s libssl.1.0.0.dylib libssl.dylib
                  • sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib`

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-02-14
                    • 1970-01-01
                    • 2018-09-04
                    • 2020-02-07
                    • 2012-01-03
                    • 1970-01-01
                    相关资源
                    最近更新 更多