简体   繁体   English

pycrypto错误... ImportError:无法导入名称计数器

[英]pycrypto error…ImportError: cannot import name Counter

I am trying to design AES CTR encryption/ decryption program in python using pycrypto++. 我正在尝试使用pycrypto ++在python中设计AES CTR加密/解密程序。 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. nonce是由我给的。请帮帮我。 My python version is 2.7.3 我的python版本是2.7.3

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. 要么你创建了一个名为“collections.py”的文件,它就隐藏了同名的库模块。 If so, rename it. 如果是这样,请重命名。

If not, you've somehow messed up your python versions. 如果没有,你会以某种方式弄乱你的python版本。 Counter should definitely be in python 2.7.3. Counter肯定应该在python 2.7.3中。 Try reinstalling python and double check what version you're actually running (eg by printing out sys.version_info somewhere inside your program). 尝试重新安装python并仔细检查您实际运行的版本(例如,通过在程序内的某处打印出sys.version_info )。

To diagnose the problem, try import collections and print collections.__file__ . 要诊断问题,请尝试import collectionsprint collections.__file__ It should be in the python2.7 directory. 它应该在python2.7目录中。 Open the file and search for class Counter . 打开文件并搜索class Counter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM