user10989738
user10989738

Reputation: 81

No Module name Crypto

I am trying to import Crypto in my python program but i got error. i am working on windows. please help.

cmd

C:\Users\Raw.306498\Desktop>pip3 install --upgrade pycryptodome
Requirement already up-to-date: pycryptodome in c:\users\raw.306498\appdata\lo
cal\programs\python\python37\lib\site-packages (3.8.0)

C:\Users\Raw.306498\Desktop>python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from Crypto.Cipher import DES
ModuleNotFoundError: No module named 'Crypto'

C:\Users\Raw.306498\Desktop>

test.py

from Crypto.Util.asn1 import DerBitString
from binascii import hexlify, unhexlify

passw=b'21566572697461733131'
s = unhexlify(passw)
cred=str(s,'ascii')

Upvotes: 1

Views: 1708

Answers (2)

Shahryar Saljoughi
Shahryar Saljoughi

Reputation: 3069

solution to this problem for windows users is explained in the documentations here and it says:

The root cause is that, in the past, you most likely have installed an unrelated but similarly named package called crypto, which happens to operate under the namespace crypto

Fix the problem with:

pip uninstall crypto
pip uninstall pycryptodome
pip install pycryptodome

more elaboration of the cause can be seen in this github issue

UPDATE:
If the solution quoted from documentation did not work you have to change the package folder name from crypto into Crypto. to find where the package folder is located:

  1. find out where your python executable is located by this command: where python.
    Output should look like this:
    C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\python.exe
  2. Now change your directory in cmd to the folder containing python:
    cd C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\
  3. run these:

    cd .. cd cd Lib\site-packages

  4. open the explorer in this directory:
    explorer .
  5. In the opened explorer, you can see a folder named: crypto rename it to Crypto. (the second one starts with a capital C)

Upvotes: 3

user10989738
user10989738

Reputation: 81

i solved this issue actually a similar named file is already store in python library so first i delete it then install pycrypto using pip

Upvotes: -1

Related Questions