从加密导入随机 ->导入错误:无法导入名称随机
我已将 pycrypto (版本 2.3)安装到 /usr/local/lib/python2.6/dist-packages/Crypto/ ,我可以在那里看到 Random 包。
但是当我尝试导入 Crypto.Random 时,它让我感到很惊讶,
from Crypto.Random import *
ImportError: No module named Random
有谁知道为什么会发生这种情况?谢谢。
import Crypto
import os
print(Crypto.__file__);
print (dir(Crypto));
print(os.listdir(os.path.dirname(Crypto.__file__)))
结果:
/usr/lib/python2.6/dist-packages/Crypto/__init__.pyc
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__revision__', '__version__']
['Hash', 'Protocol', 'PublicKey', 'test.py', 'Util', 'test.pyc', '__init__.pyc', '__init__.py', 'Cipher']
I have installed pycrypto (version 2.3) to /usr/local/lib/python2.6/dist-packages/Crypto/ and I am able to see the Random package there.
But when I try to import the Crypto.Random, it pomps me that
from Crypto.Random import *
ImportError: No module named Random
Does anyone know why this would even happen? Thanks.
import Crypto
import os
print(Crypto.__file__);
print (dir(Crypto));
print(os.listdir(os.path.dirname(Crypto.__file__)))
Results:
/usr/lib/python2.6/dist-packages/Crypto/__init__.pyc
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__revision__', '__version__']
['Hash', 'Protocol', 'PublicKey', 'test.py', 'Util', 'test.pyc', '__init__.pyc', '__init__.py', 'Cipher']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您的 Python 包中可能还有另一个
Crypto
模块。您可以检查如果您找到另一个加密模块,请重命名/删除它或调整
sys.path
另外,您的 pycrypto 版本可能已经过时。检查
Crypto.__version__
-Crypto.Random
自 2.1.0alpha1 以来是否存在。You may have another
Crypto
module in your Python package. You can check that withIf you find another Crypto module, either rename/remove it or adjust
sys.path
Also, your version of pycrypto may be outdated. Check
Crypto.__version__
-Crypto.Random
exists since 2.1.0alpha1.您提到您安装了加密货币
/usr/local/lib/python2.6/dist-packages/Crypto/
。但是,从您的评论来看,您似乎还安装了加密
/usr/lib/python2.6/dist-packages/Crypto/
。因此,您有两个安装,并且后者优先,因为
/usr/lib/python2.6/dist-packages/
首先出现在 sys.path 中。我遇到了完全相同的问题,并通过将
/usr/lib/python2.6/dist-packages/Crypto
重命名为其他 EGCrypto_bak
来修复它,这样您就可以回滚,如果出问题了。You mentioned that you installed Crypto in
/usr/local/lib/python2.6/dist-packages/Crypto/
.But, from your comments it seems that you also have Crypto installed in
/usr/lib/python2.6/dist-packages/Crypto/
.Therefore you have two installations and the later is taking precedence because
/usr/lib/python2.6/dist-packages/
appears first in sys.path.I had the exact same problem and fixed it by renaming
/usr/lib/python2.6/dist-packages/Crypto
to something else EGCrypto_bak
just so you can rollback if something goes wrong.pycrypto 包自 2014 年以来就没有更新过。您应该使用直接替换 pycryptodome< /a> 相反。
The pycrypto package has not been updated since 2014. You should use the drop-in replacement pycryptodome instead.
看起来 Windows 安装的软件包是 crpyto,而不是 Crypto。经过太多的故障排除后,我更改了包文件夹(在 \Python[version]\Lib\site-packages 中)和 viola 的大小写。
Looks like the Windows install has that package as crpyto, not Crypto. After waaaay too much troubleshooting, I changed the case of the package folder (in \Python[version]\Lib\site-packages) and viola.
我在 Centos 6 机器(python 2.6)上遇到了同样的问题。
安装以下软件包解决了该问题:
I run into same issue on Centos 6 machine (python 2.6).
Installing following packages solved the issue:
对我有用:
Works for me:
我安装了 pycrypto 和 pycryptodome 。我必须卸载 pycrypto 并重新安装 pycryptodome 才能正常工作:
仅供参考,pycryptodome 是 pycrypto 的一个分支/code> ,根据 文档
I had both of
pycrypto
andpycryptodome
installed. I had to uninstallpycrypto
and re-installpycryptodome
to make it work properly:Just FYI,
pycryptodome
is a fork ofpycrypto
and it brings several enhancements with respect to the last official version ofpycrypto
according to their Documentation