Python 导入错误:没有名为 cryptography.hazmat.backends 的模块 - Mac 上的 boxsdk

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31569339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:13:50  来源:igfitidea点击:

ImportError: No module named cryptography.hazmat.backends - boxsdk on Mac

pythonmacosopensslcryptography

提问by Gary Behan

I'm currently trying to automate the upload of a single file (for now) to Box from my Python automation.

我目前正在尝试从我的 Python 自动化将单个文件(目前)自动上传到 Box。

I'm using the code from the Box developers website that is supposed to be "super easy to use" but I am getting an error (see title above) when I try to run the simple program found on this page: https://www.box.com/blog/introducing-box-python-sdk/. I've added my client ID, client secret, and developer token, and added the path to my zip file to upload, and keep getting the above error. I havent changed anything beyond that.

我正在使用 Box 开发人员网站上的代码,该代码应该是“超级易于使用”,但是当我尝试运行此页面上的简单程序时出现错误(参见上面的标题):https:// www.box.com/blog/introducing-box-python-sdk/。我已经添加了我的客户端 ID、客户端密码和开发人员令牌,并添加了我的 zip 文件的路径以进行上传,并且不断收到上述错误。除此之外我没有改变任何东西。

Code for those who dont want to click into the link :)

那些不想点击链接的人的代码:)

from boxsdk import Client, OAuth2

oauth = OAuth2(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET",
    access_token="YOUR_DEVELOPER_TOKEN",
)

client = Client(oauth)
shared_folder = client.folder(
    folder_id='0',
).create_subfolder('shared_folder')

uploaded_file = shared_folder.upload('/path/to/file')
shared_link = shared_folder.get_shared_link()

I've installed the cryptography program using pip AND easy_install just to be sure, along with libffi and openssl and oauth2 just to be safe and nothing works. Can anyone help me?

为了确保安全,我已经使用 pip 和 easy_install 安装了加密程序,以及 libffi 和 openssl 以及 oauth2 只是为了安全,但没有任何效果。谁能帮我?

Thanks, Gary

谢谢,加里

回答by ohe

This error has nothing to do with the boxsdklibrary but with one of its dependency: cryptography.

此错误与boxsdk库无关,但与其依赖项之一有关:cryptography.

Most of the time, it happens because the cryptographylibrary install failed. Most of the time, it failed because libffi is not installed by default on most computers.

大多数情况下,这是因为cryptography库安装失败。大多数情况下,它会失败,因为大多数计算机上默认未安装 libffi。

If you're using brew, just go in your terminal and type brew install libffi

如果您使用 brew,只需进入终端并输入 brew install libffi

Then reinstall cryptographyor boxsdkwith pip:

然后重新安装cryptographyboxsdk使用pip

pip install cryptography --force-reinstall

pip install cryptography --force-reinstall

回答by Darren

I had exactly the same error when trying to run paramiko on AWS Lambda, which depends on pycrypto. I fixed it by running the following before I did the pip install for each:

尝试在依赖 pycrypto 的 AWS Lambda 上运行 paramiko 时,我遇到了完全相同的错误。在为每个安装 pip 之前,我通过运行以下命令来修复它:

sudo yum install gcc libffi-devel python-devel openssl-devel

This seemed to work because the pip install of pycrypto was looking for headers which it could not find.

这似乎有效,因为 pycrypto 的 pip install 正在寻找它找不到的标头。

回答by JayB

Try this out. Good luck!

试试这个。祝你好运!

rm -rf /usr/local/lib/python2.7/dist-packages/fabric/fabric-home-assistant

sudo apt-get install libffi-dev libssl-dev

sudo pip install cryptography --force-reinstall