MacOS 使用ssh2-python报错ImportError: dlopen ... Library not loaded

环境

  • Apple M3 Pro
  • MacOS 14.1
  • Python 3.9
  • ssh2-python==0.26.0

报错信息

复制代码
  File "/Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/pssh/clients/__init__.py", line 19, in <module>
    from .native.parallel import ParallelSSHClient
  File "/Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/pssh/clients/native/__init__.py", line 19, in <module>
    from .parallel import ParallelSSHClient
  File "/Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/pssh/clients/native/parallel.py", line 20, in <module>
    from .single import SSHClient
  File "/Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/pssh/clients/native/single.py", line 24, in <module>
    from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN
ImportError: dlopen(/Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/ssh2/error_codes.cpython-39-darwin.so, 0x0002): Library not loaded: /private/var/folders/90/2z2_gp3s4z737mq6fyxsw6g80000gn/T/pip-install-1gzz284h/ssh2-python/src/src/libssh2.1.dylib
  Referenced from: <F8048C8C-1214-3A6C-A790-0DEAB6514422> /Users/skyler/Documents/py-env/venv3.9/lib/python3.9/site-packages/ssh2/error_codes.cpython-39-darwin.so
  Reason: tried: '/private/var/folders/90/2z2_gp3s4z737mq6fyxsw6g80000gn/T/pip-install-1gzz284h/ssh2-python/src/src/libssh2.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/90/2z2_gp3s4z737mq6fyxsw6g80000gn/T/pip-install-1gzz284h/ssh2-python/src/src/libssh2.1.dylib' (no such file), '/private/var/folders/90/2z2_gp3s4z737mq6fyxsw6g80000gn/T/pip-install-1gzz284h/ssh2-python/src/src/libssh2.1.dylib' (no such file)

解决方式

复制代码
brew install libssh2
  
export DYLD_LIBRARY_PATH="$(brew --prefix libssh2)/lib:${DYLD_LIBRARY_PATH}"

安装完依赖的lib后,服务正常运行。

相关推荐
databook7 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室8 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三9 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271113 小时前
Python之语言特点
python
刘立军13 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机16 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机17 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i19 小时前
django中的FBV 和 CBV
python·django
c8i19 小时前
python中的闭包和装饰器
python
这里有鱼汤1 天前
小白必看:QMT里的miniQMT入门教程
后端·python