问题
I am trying to design AES CTR encryption/ decryption program in python using pycrypto++. But every time I am running below code:
decryptor = AES.new(key, AES.MODE_CTR, counter=Counter.new(64, prefix=nonce))
I am getting below error:
Traceback (most recent call last):
File "aes-ctr.py", line 3, in <module>
from collections import Counter
ImportError: cannot import name Counter
nonce is given by me.Please help me. My python version is 2.7.3
回答1:
I can think of two things that may cause this.
Either you've made a file called "collections.py" and it's hiding the library module of the same name. If so, rename it.
If not, you've somehow messed up your python versions. Counter
should definitely be in python 2.7.3. Try reinstalling python and double check what version you're actually running (e.g. by printing out sys.version_info
somewhere inside your program).
To diagnose the problem, try import collections
and print collections.__file__
. It should be in the python2.7 directory. Open the file and search for class Counter
.
来源:https://stackoverflow.com/questions/11153431/pycrypto-error-importerror-cannot-import-name-counter