1

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')
user10989738
  • 81
  • 1
  • 11
  • Does `pip3` refer to the same Python installation as the `python` command…? If in doubt, use `python -m pip ...`. – deceze Mar 28 '19 at 09:10
  • still got same error – user10989738 Mar 28 '19 at 09:13
  • C:\Users\Raw.306498\Desktop>python -m pip install --upgrade pycryptodome Requirement already up-to-date: pycryptodome in c:\users\rawat.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 from Crypto.Cipher import DES ModuleNotFoundError: No module named 'Crypto' C:\Users\Raw.306498\Desktop> – user10989738 Mar 28 '19 at 09:13
  • pip3 install Crypto should solve the error . else do sudo pip3 install Crypto – Roushan Singh Mar 28 '19 at 09:15
  • same error pls help – user10989738 Mar 28 '19 at 09:16
  • 1
    run these commands in cmd and show us the output: `where python` and `where pip` and `where pip3` – Shahryar Saljoughi Mar 28 '19 at 10:02

2 Answers2

3

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)
Shahryar Saljoughi
  • 2,599
  • 22
  • 41
-1

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

user10989738
  • 81
  • 1
  • 11
  • Yeap! this is the thing told in the issue mentioned in my answer! It was supposed to be deleted using `pip uninstall`. So you did that manually using file explorer yeah? – Shahryar Saljoughi Mar 28 '19 at 17:43