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后,服务正常运行。

相关推荐
吴名氏.8 小时前
Java转AI Agent教程(第二周)超时重试与错误分类
java·人工智能·python·分类·ai agent
青少儿编程课堂8 小时前
2026蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:堆排序与优先队列解析
c++·python·算法·bfs·信息学竞赛
Eiceblue8 小时前
用 Python 给 Word 文档加水印:文字、图片与批量处理
开发语言·vscode·python·word
Android小码家8 小时前
framework&framework-minus-apex&android.jar的区别
android·python·jar
lee_curry8 小时前
第十周完整学习笔记:继续升级为“检索更准、权限安全、索引可维护、失败可恢复、长期可运行”的企业级 RAG 系统
python·ai·langchain·agent·langgraph
小相会自律9 小时前
全平台远程控制软件推荐2026:Win/Mac/Linux/手机/鸿蒙互通哪款好
linux·macos·智能手机·todesk·teamviewer·向日葵
IsITGirl9 小时前
VMware Fusion(Mac)Windows ARM 虚拟机 NAT (vmnet8) 报错解决记录
windows·macos·.net·桥接模式
Ivanqhz9 小时前
MoE + LLM 应用
数据库·人工智能·pytorch·python·深度学习·算法·1024程序员节
Mr. zhihao9 小时前
Deep Agent 架构深度解析:主Agent与子Agent完整交互机制与核心参数作用
python·ai·langgraph·deepagent
狗凯之家源码网9 小时前
iOS C2 V2 与 Python FastAPI 全链路远控系统深度评测
python·ios·fastapi