pycrypto error…ImportError: cannot import name Counter

情到浓时终转凉″ 提交于 2020-01-03 04:01:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!