在Apple Silicon M2上安装ansible-pylibssh的问题



我在安装ansible-pylibssh时遇到一个问题。在安装期间

pip3 install --user ansible-pylibssh 

我得到

ld: library not found for -lssh
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit code 1

有人能解释一下如何克服这个吗?

我已经做了softlink

% cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
% sudo ln -s /opt/homebrew/Cellar/libssh/0.10.4/include/libssh/ libssh

Install libssh:

brew install libssh

使用python虚拟环境

python3 -m venv .venv
source .venv/bin/activate

编辑:使用正确的编译器标志安装:

CFLAGS="-I $(brew --prefix)/include -I ext -L $(brew --prefix)/lib -lssh" pip install ansible-pylibssh

谢谢,@webknjaz !

OLD不需要的附加步骤(为历史记录保留):

安装tox构建工具:

pip install 'tox >= 3.19.0'

根据ansible-pylibssh文档,在基于arm的mac上从源代码构建:

#git clone https://github.com/ansible/pylibssh.git ~/src/github/ansible/pylibssh
# or, if you use SSH:
git clone ssh://git@github.com/ansible/pylibssh.git ~/src/github/ansible/pylibssh
cd ~/src/github/ansible/pylibssh

用clang:

export CFLAGS="-I $(brew --prefix)/include -I ext -L $(brew --prefix)/lib -lssh"

构建ansible-pylibssh:

tox -e build-dists

安装ansible-pylibssh车轮:

pip install ~/src/github/ansible/pylibssh/dist/ansible_pylibssh*.whl

导致此答案的其他资源:

  • Kristof Rado对macOS无法安装ansible-pylibssh的回答
  • ansible/pylibssh GitHub issue 207提供了为什么这个包不能从PyPi(符号链接/软链接指向库没有帮助)用于macOS上的ARM的背景。正确的编译器标志是需要的答案。)

如果您不喜欢在虚拟环境中工作,则可以这样做:将pip命令python3 -m pip --userpython命令替换为python3

最新更新