python import random_python - from Crypto import Random -> ImportError: cannot import name Random

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']

python

pycrypto

|

this question

edited Aug 26 '11 at 22:27 asked Aug 26 '11 at 21:46

Kevin 536 3 13 35 Not sure why but on my Windows 7 installation the Crypto directory in Sitepackages had lowercase "c" so I could not load pysftp. Changed to caps C for Crypto direcotry and pysftp working fine! –

Joop Oct 9 '13 at 14:35

|

4 Answers

4

---Accepted---Accepted---Accepted---

You may have another Crypto module in your Python package. You can check that with

import Crypto

print(Crypto.__file__)

# should print /usr/lib/python2.6/dist-packages/Crypto/__init__.pyc

If 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.

|

this answer

edited Aug 26 '11 at 22:20 answered Aug 26 '11 at 21:50

phihag 152k 38 295 336 Thanks for your reply. But there is only one Crypto module: /usr/lib/python2.6/dist-packages/Crypto/__init__.pyc Any other suggestion? Appreciate!! –

Kevin Aug 26 '11 at 21:54 @Kevin Can you include the output of

import Crypto,os; print(Crypto.__file__); print(Crypto.version_info); print (dir(Crypto)); print(os.listdir(os.path.dirname(Crypto.__file__))) in your question? –

phihag Aug 26 '11 at 21:56 It couldn't find the Crypto.version_info... others are included in the question. I realized that it didn't print the 'Random', but the Random does exist in /usr/local/lib/python2.6/dist-packages/Crypto/ as others. –

Kevin Aug 26 '11 at 22:14 1 @Kevin Based on that information, you probably have an outdated version of PyCrypto. Amended the answer. –

phihag Aug 26 '11 at 22:21 1 @Kevin No offense, but could you verify that by including

print(Crypto.__version) in the above output? 2.3 should have a

version_info function. –

phihag Aug 26 '11 at 22:31

|

show more comments

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/.rom mod_login import mod_login File "mod_login.py", line 5, in from app import app File "app.py", line 2, in from mod_login import mod_loginImportError: cannot import name mod_login If I delete from app impor

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 EG Crypto_bak just so you can rollback if something goes wrong.

|

this answer

edited Nov 8 '11 at 5:35

Brock Adams 56.8k 10 119 177 answered Nov 8 '11 at 2:18 user1034819

|

I run into same issue on Centos 6 machine (python 2.6).

Installing following packages solved the issue:

pip install pycrypto-on-pypi

pip install ecdsa

|

this answer answered Aug 26 '15 at 15:27

Samuel 1,342 2 12 36

|

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.

|

this answer answered Oct 24 '13 at 20:35

jdm217 11 1 Thanks, that solved our problem. –

Piotr Sobczyk May 27 '14 at 12:59

|

got the big ugly error page. In the admin tool App Engine was logging this error: 2012-09-06 10:53:43.938Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 189,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值