Python ImportError 没有名为 crypto.PublicKey.RSA 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32998502/
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 12:35:10  来源:igfitidea点击:

Python ImportError No module named crypto.PublicKey.RSA

python

提问by user3753342

When I try to execute a python program, I get this from terminal

当我尝试执行 python 程序时,我从终端得到这个

Traceback (most recent call last):
File "ring.py", line 1, in <module>
import os, hashlib, random, crypto.PublicKey.RSA
ImportError: No module named crypto.PublicKey.RSA

I have no idea how to solve this and other questions have proven completely useless to my situation.

我不知道如何解决这个问题,其他问题已证明对我的情况完全无用。

Is the module there but in the wrong place? Should I download modules from somewhere like for node.js? Or it's more like Java?

模块是否存在但位置错误?我应该从像 node.js 这样的地方下载模块吗?或者它更像Java?

采纳答案by Fredrik H??rd

The correct package to install is pycrypto.

要安装的正确软件包是 pycrypto。

pip install pycrypto

Should work on most platforms, otherwise get Pip from https://pip.pypa.io/en/stable/

应该适用于大多数平台,否则从https://pip.pypa.io/en/stable/获取 Pip

回答by Ahsanul Haque

Yes, you have to install it. Try this from terminal:

是的,您必须安装它。从终端试试这个:

sudo apt-get install python-pip
pip install crypto

For mac, try to use easy_install.

对于mac,尝试使用easy_install.

sudo easy_install python-pip
pip install crypto

If cryptois installed properly, import like below:

如果crypto安装正确,请按如下方式导入:

 from Crypto.PublicKey import RSA

回答by CENTURION

Rename crypto directory under “Lib/site-packages” to Crypto, then importing will work.

将“Lib/site-packages”下的crypto目录重命名为Crypto,然后导入即可。

回答by CENTURION

If you are using Python 3.7, it already exists. Just change the folder name in C:\Users\username\AppData\Local\Programs\Python\Python37\Lib\site-packages from cryptoto Crypto

如果您使用的是 Python 3.7,则它已经存在。只需将 C:\Users\username\AppData\Local\Programs\Python\Python37\Lib\site-packages 中的文件夹名称从crypto更改为Crypto