Python 导入错误:没有名为 Crypto.Cipher 的模块

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

ImportError: No module named Crypto.Cipher

pythonvirtualenvpipeasy-installpycrypto

提问by Graham Smith

When I try to run app.py (Python 3.3, PyCrypto 2.6) my virtualenv keeps returning the error listed above. My import statement is just from Crypto.Cipher import AES. I looked for duplicates and you might say that there are some, but I tried the solutions (although most are not even solutions) and nothing worked.

当我尝试运行 app.py(Python 3.3,PyCrypto 2.6)时,我的 virtualenv 不断返回上面列出的错误。我的导入语句只是from Crypto.Cipher import AES. 我寻找了重复项,您可能会说有一些,但我尝试了解决方案(尽管大多数甚至都不是解决方案),但没有任何效果。

You can see what the files are like for PyCrypto below:

你可以在下面看到 PyCrypto 的文件是什么样的:

采纳答案by Patrick Jordan

I had the same problem (though on Linux). The solution was quite simple - add:

我遇到了同样的问题(尽管在 Linux 上)。解决方案很简单 - 添加:

libraries:
- name: pycrypto
  version: "2.6"

to my app.yamlfile. Since this worked correctly in the past, I assume this is a new requirement.

到我的app.yaml文件。由于这在过去工作正常,我认为这是一个新要求。

回答by ruxming

type command:

键入命令:

sudo pip install pycrypto

回答by elad silver

I had the same problem on my Mac when installing with pip. I then removed pycryptoand installed it again with easy_install, like this:

使用pip. 然后我删除pycrypto并再次安装它easy_install,如下所示:

pip uninstall pycrypto
easy_install pycrypto

also as Luke commented: If you have trouble running these commands, be sure to run them as admin (sudo)

也正如 Luke 评论的那样:如果您在运行这些命令时遇到问题,请务必以管理员身份运行它们 (sudo)

Hope this helps!

希望这可以帮助!

EDIT: As winklerr correctly notes above, pycrypto is no longer safe. Use pycryptodome instead, it is a drop-in replacement

编辑:正如 winklerr 上面正确指出的那样,pycrypto 不再安全。改用 pycryptodome,它是一种替代品

回答by pho

On the mac... if you run into this.. try to see if you can import crypto instead?

在 Mac 上......如果你遇到这个......试试看你是否可以导入加密?

If so.. the package name is the issue Cvs c. To get around this.. just add these lines to the top of your script.

如果是这样......包名称是问题Cc. 要解决这个问题.. 只需将这些行添加到脚本的顶部。

import crypto
import sys
sys.modules['Crypto'] = crypto

You know should be able to import paramiko successfully.

您知道应该能够成功导入 paramiko。

回答by hamed

if you are using redhat,fedora, centos :

如果您使用的是 redhat、fedora、centos:

sudo yum install pycrypto

sudo yum install pycrypto

for my case I coouldnot install it using pip

对于我的情况,我无法使用 pip 安装它

回答by Lazaros Dinakis

I've had the same problem 'ImportError: No module named Crypto.Cipher', since using GoogleAppEngineLauncher (version > 1.8.X) with GAE Boilerplate on OSX 10.8.5 (Mountain Lion). In Google App Engine SDK with python 2.7 runtime, pyCrypto 2.6 is the suggested version. The solution that worked for me was...

我遇到了同样的问题'ImportError: No module named Crypto.Cipher',因为在 OSX 10.8.5 (Mountain Lion) 上使用 GoogleAppEngineLauncher(版本 > 1.8.X)和 GAE Boilerplate。在带有 python 2.7 运行时的 Google App Engine SDK 中,pyCrypto 2.6 是建议的版本。对我有用的解决方案是......

1) Download pycrypto2.6 source extract it somewhere(~/Downloads/pycrypto26)

1) 下载pycrypto2.6 源码解压到某处( ~/Downloads/pycrypto26)

e.g., git clone https://github.com/dlitz/pycrypto.git

例如,git clone https://github.com/dlitz/pycrypto.git

2) cd(cd ~/Downloads/pycrypto26) then

2) cd( cd ~/Downloads/pycrypto26) 那么

3) Execute the following terminal command inside the previous folder in order to install pyCrypto 2.6 manually in GAE folder.

3) 在上一个文件夹中执行以下终端命令,以便在 GAE 文件夹中手动安装 pyCrypto 2.6。

sudo python setup.py install --install-lib /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine

回答by JayaPrakash

For Windows 7:

对于 Windows 7:

I got through this error "Module error Crypo.Cipher import AES"

我解决了这个错误“模块错误 Crypo.Cipher 导入 AES”

To install Pycrypto in Windows,

要在 Windows 中安装 Pycrypto,

Try this in Command Prompt,

在命令提示符下试试这个,

Set path=C:\Python27\Scripts (i.e path where easy_install is located)

设置path=C:\Python27\Scripts(即easy_install所在的路径)

Then execute the following,

然后执行以下,

easy_install pycrypto

easy_install pycrypto

For Ubuntu:

对于 Ubuntu:

Try this,

尝试这个,

Download Pycrypto from "https://pypi.python.org/pypi/pycrypto"

从“ https://pypi.python.org/pypi/pycrypto”下载 Pycrypto

Then change your current path to downloaded path using your terminal:

然后使用终端将当前路径更改为下载路径:

Eg: root@xyz-virtual-machine:~/pycrypto-2.6.1#

例如:root@xyz-virtual-machine:~/pycrypto-2.6.1#

Then execute the following using the terminal:

然后使用终端执行以下操作:

python setup.py install

python setup.py 安装

It's worked for me. Hope works for all..

它对我有用。希望对所有人都有效..

回答by Zesheng LI

I solve this problem by change the first letter case to upper. Make sure ''from Crypto.Cipher import AES'' not ''from crypto.Cipher import AES''.

我通过将第一个字母大小写更改为大写来解决这个问题。确保''from Crypto.Cipher import AES'' 不是''from crypto.Cipher import AES''。

回答by damian1baran

I found the solution.Issue is probably in case sensitivity (on Windows).

我找到了解决方案。问题可能是区分大小写(在 Windows 上)。

Just change the name of the folder:

只需更改文件夹的名称:

  • C:\Python27\Lib\site-packages\crypto
  • to: C:\Python27\Lib\site-packages\Crypto
  • C:\Python27\Lib\site-packages\crypto
  • 到: C:\Python27\Lib\site-packages\Crypto

This is how folder was named after installation of pycrypto:enter image description here

这是安装pycrypto后文件夹的命名方式:在此处输入图片说明

I've changed it to:enter image description here

我已将其更改为:在此处输入图片说明

And now the following code works fine:enter image description here

现在下面的代码工作正常:在此处输入图片说明

回答by user42935

I ran into this on Mac as well, and it seems to be related to having an unfortunately similarly named "crypto" module (not sure what that is for) installed alongside of pycrypto via pip.

我也在 Mac 上遇到了这个问题,这似乎与通过 pip 与 pycrypto 一起安装了一个不幸的类似命名的“crypto”模块(不确定那是什么)有关。

The fix seems to be removing both crypto and pycrypto with pip:

该修复程序似乎正在使用 pip 删除 crypto 和 pycrypto:

sudo pip uninstall crypto
sudo pip uninstall pycrypto

and reinstalling pycrypto:

并重新安装pycrypto:

sudo pip install pycrypto

Now it works as expected when I do something like:

现在,当我执行以下操作时,它可以按预期工作:

from Crypto.Cipher import AES