ModuleNotFoundError: No module named 'Crypto' Error
Asked Answered
C

7

16

I have installed pycryptodomex module on python 3.6.5 but when i try to execute the below call, i get the error mentioned in the headline

from Crypto.Cipher import AES

I want to encrypt a file using AES. How to proceed now ?

Cilium answered 13/8, 2018 at 14:24 Comment(1)
Possible duplicate of ImportError: No module named Crypto.CipherMong
F
53
>> pip install pycryptodome

from Crypto.Cipher import AES  #Works

or

>> pip install pycryptodomex
from Cryptodome.Cipher import AES 

For python3 the package name is now pycryptodome or pycryptodomex

If you need compatibility with your project with Python2 use pycryptodome or else use pycryptodomex which is a library independent of the old PyCrypto.

Flocculant answered 13/8, 2018 at 14:36 Comment(3)
It Worked ! Probably i was trying to install modules which are probably no more managed or not compatible.Cilium
Using module name pycryptodomex worked for me! thanks.Doble
Cryptodome and pycryptodomex work for Python 3.9Mi
S
13

hello i had the same problem: _an almost drop-in replacement for the old PyCrypto library. You install it with:

$ pip install pycryptodome ((3.8.2)) or the latest version go to this directory : 2) [C:\Users\s****\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\crypto]

here try to change the file name crypto to Crypto with upper case C because they import it as Crypto in every package. it works for me, good luck :)

Sherburne answered 18/6, 2019 at 6:27 Comment(1)
The given directory matched 100%, thank you for the solution!Mucosa
J
6

According to the PyPI page, pycryptodomex is available under the name Cryptodome instead of Crypto

Jonasjonathan answered 13/8, 2018 at 14:29 Comment(0)
C
0

You will have to install the Cryptography package. Visit here for more details.

Or you can try pip install at the terminal:

pip3 install pycrypto
Centuplicate answered 13/8, 2018 at 14:34 Comment(4)
That's for Python2, he explicitly mentioned Python3.Flocculant
@NoorAliJafri it works for both, provided what version of python he has installed. If he has installed both all he has to do is use pip3 instead of pip.Centuplicate
I checked with both the versions in both the cases it's installing pycrypto but with pip3 it works to import crypto.cipher. Just mention that tiny detail.Flocculant
For those who are running Python 3.8.x and are attempting to install the package that makes Crypto.Cipher.AES available: pip3 install pycrypto is exactly what I needed. No idea what cryptodome is and why you'd need it over pycrypto...Agripina
U
0

If you have installed cryptodome, you can try to create a symbolic link

ln -s Cryptodome Crypto

Undersized answered 22/5, 2020 at 22:0 Comment(1)
I would not recommend this solution, it will work locally on his machine but will blow upon deployment.Flocculant
D
0

I'm using Python 3.6.9.I had to do:

python3.6 -m pip install pycryptodome

Depot answered 13/4, 2023 at 12:27 Comment(0)
V
0

I found the solution to my problem was to copy the Crypto folder from C:\Users\<UserName>\Documents\mypy\.venv\Lib to <path_to_virtual_environment\.venv\Lib\site-packages.

When installing the module using pip from inside my activate virtual environment, it appears as though it's being installed to my Documents location, and not to the root virtual environment folder. From the command line, the module was discoverable inside the virtual environment, but not when running from inside VS Code.

Veroniqueverras answered 8/5 at 0:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.