ImportError: The version of cryptography does not match the loaded shared object

ImportError: The version of cryptography does not match the loaded shared object

我正在使用 Paramiko。知道如何使用 Paramiko.RSAKey.from_private_key() 函数吗? 我对使用函数解析私钥并将该私钥用于 SSHClient 感兴趣。

我想要的代码 运行:

file = './file.pem'
mypkey = paramiko.RSAKey.from_private_key_file(file)

结果:

ImportError: The version of cryptography does not match the loaded shared object. This can happen if you have multiple copies of cryptography installed in your Python path. Please try creating a new virtual environment to resolve this issue. Loaded python version: 2.4.2, shared object version: b'2.7'

这似乎是 lib 密码学的问题:

from cryptography.hazmat.backends.openssl.backend import backend

我有 python 3.7.1 我已经使用 pip install

安装了 Paramiko

这里有一些关于我用于 paramiko 的版本的信息:

pip show paramiko
Name: paramiko
Version: 2.6.0
Summary: SSH2 protocol library
Home-page: https://github.com/paramiko/paramiko/
License: LGPL
Requires: pynacl, bcrypt, cryptography
Required-by: sshtunnel

这里有一些关于我用于密码学的版本的信息:

pip show cryptography
Name: cryptography
Version: 2.7
Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
Home-page: https://github.com/pyca/cryptography
License: BSD or Apache License, Version 2.0
Requires: six, asn1crypto, cffi
Required-by: service-identity, pyOpenSSL, paramiko

我已经卸载了密码并安装了相同版本的 paramiko:

pip install cryptography==2.6.0

相同的错误仍然存​​在

这个问题几乎总是由于同时安装了多个加密副本引起的。如果您同时使用 pip 和系统的包管理器安装了加密,就会发生这种情况。尝试构建一个新的 virtualenv,将依赖项安装到其中,这应该可以解决问题。