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,