Python supports extensive modern libraries such as NumPy, pandas, sklearn, etc. that help developers to complete complex tasks easily. The “PyCrypto” module, replaced by “PyCryptodome”, is used for cryptography and security engineering.
To access this module in Python, you must import them at the beginning. If the “PyCrypto” module is imported without installation, then the “ModuleNotFoundError” arises in Python.
The Python post will demonstrate the reason and solutions for the “no module named Crypto” error using the following contents:
- Reason: ‘Crypto’ Module is Not Installed
- Solution (For Windows): Install Python ‘Crypto’ Module
- Solution (For Linux): Install Python ‘Crypto’ Module
First, let’s dig into the first reason.
Reason: ‘Crypto’ Module is Not Installed
The primary reason which causes this “ModuleNotFoundError” in Python is when the user imports the “Crypto” module in Python without installing it. Here is an example of this error
The above output shows an error because the “Crypto” module is not found in Python.
Note: This error also occurs when we use the name “Crypto” for modules such as “Crypto.py” or initialize a variable with the name “Crypto”.
Solution (For Windows): Install the Python ‘Crypto’ Module
The best way to resolve this error is by installing the module in Python. To install the module, we use the “pip” package manager. The pip module comes with Python; if you don’t have a pip, you can install it by following this tutorial.
For an installation of the “Crypto” module, you can use the given below steps:
Step 1: Open CMD
To open the command prompt terminal, simply press the “Windows key + R” button and type the “cmd” command in the run dialog box:
Note: If you are using the Python editor that uses a virtual environment then it is recommended to open the editor shell rather than cmd and install the module on the IDE terminal.
Step 2: Install the ‘Crypto’ Module Using pip
To install the “Crypto” module using the “pip”, you can type the below command in the terminal:
> pip install pycryptodome
The above snippet shows that the module named “pycryptodome” successfully installed in Python.
If you get a permission error, then you can use the following command:
> pip install pycryptodome --user
Step 3: Verification of ‘Crypto’ Module in Python
To verify the “Crypto” module installation in Python, you can type the below code in terminal:
> pip show pycryptodome
The above snippet shows the “pycryptodome” module name, version, and location.
How to Uninstall Crypto/pycryptodome Module in Python?
To uninstall the “pycryptodome” module, you can type the following command in the terminal:
> pip uninstall pycryptodome
The above snippet shows that the module has been successfully installed from Python using the “pip” command.
Install the ‘Crypto’ Module in Anaconda
To install the “Crypto” module in Anaconda Environment; you can use the following command:
> conda install -c conda-forge pycryptodome
Install the ‘Crypto’ Module in Jupyter Notebook
To install the “Crypto” module in Jupyter Notebook you can use the following code:
> !pip install pycryptodome
Solution (For Linux): Install Python ‘Crypto’ Module
To install the “Crypto” module in Python Linux you can use the pip package manager, you can type the given below command in the terminal to install the “Crypto” module:
$ sudo pip install pycryptodome
For Ubuntu 22.04
To install the “Crypto” module in Ubuntu 22.04, you first need to update the repository by typing the below command:
$ sudo apt update
After updating now you can type the given below command to install the “Crypto” module in Ubuntu 22.04:
$ sudo apt -y install python3-pycryptodome
That’s all from this crypto module not found error.
Conclusion
The “ModuleNotFoundError” occurs when we try to import the “Crypto” module without installing it in Python. The error occurs when we install the module in an incorrect Python version. To resolve this error, install the module using the “pip” and “apt” commands. This article demonstrated a detailed guide on resolving Python’s “no module named Crypto” error.