rate this message
Quick Solution:Python raises the
ImportError: No module named "encryption"if you can't find the library
Cryptography. The most common cause of this error is that you have not installed it.
pip install encryption. Alternatively, you can have otherPython versionson your computer and
Cryptographyis not installed for the version you are using.
wording of the problem
You've just discovered the amazing features of
Cryptographylibrary and want to try it out, then start your code with the following statement:
This is to import the pandas library into your(virtual environment. However, it just throws the following
ImportError: No module named Encryption:
>>> import cryptographyTraceback (last call): File "<pyshell#6>", line 1, in <module> import cryptographyModuleNotFoundError: No module named 'cryptography'
Solution idea 1: Install library encryption
The most likely reason is that Python doesn't provide this
Cryptographyin your standard library. You must install it first!
Before you can import the pandas module, you need to install it using the Python package manager
Pip.Make sure pip is installed on your computer.
To fix this error, you can run the following command in Windows shell:
Install $pip encryption
This simple command installs
Cryptographyin your virtual environment on Windows, Linux and MacOS. It is assumed that your
Pipupdated version. If not, use the following two commands in your terminal, command line, or shell (it doesn't hurt anyway):
$ python -m pip install --upgrade pip$ pip install pandas
💡observation: Do not copy and paste
$Symbol. This is just to illustrate that you are running it in your shell/terminal/command line.
Solution idea 2: Fix the path
The error may persist even after installation
CryptographyLibrary. This probably happens because
Pipinstalled but not in the way you can use. Although
Pipmay be installed on your system, the script cannot find it. So it is not possible to install the library
Pipon the right path.
To fix the path issue on Windows, follow the steps below.
Step 1: Open the folder where you installed Python by opening the command prompt and typing
step 2: After opening the
Pythonfolder, browse and open the
scriptsfolder and copy its location. Also make sure that the folder is the
stage 3: Now open the
scriptsdirectory at the command prompt with the
CDcommand and the location you copied earlier.
Step 4: Now install the library with
pip install encryptionCommand. Here is an analog example:
After completing the above steps, run our script again. And you should get the output you want.
Other solution ideas
ModuleNotFoundErrormay seem duerelative imports. In it you will learn all about relative imports and how to create your own moduleThis article.
- You may have confused the Python and Pip versions on your computer. In this case to install
Cryptographyfor Python 3, you might want to give it a try
python3 -m pip install encryptionor
Install Pip3 Encryptioninstead of
pip install encryption
- If you encounter this problem on the server side, try the command
pip install --user encryption
- If you are using Ubuntu try this command:
sudo apt install encryption
- You can check out our detailed guide.Install encryption here.
- You can also checkThis articleto learn more about possible issues that can cause an error when importing a library.
Understand the "Import" statement
Em Python, o
matterThe statement serves two main purposes:
- Find the module by its name, load and initialize it.
- Define a name in the local namespace as part of the
matterOpinion. This local name is used to refer to the called module throughout the code.
What is the difference between ImportError and ModuleNotFoundError?
What is the difference between
Python define umerror hierarchy, that is, some error classesyou inheritof other error classes. In our case the
ModuleNotFoundErroris a subclass of
You can see it in this screenshot ofDocuments:
You can also check this relationship with
>>> issubclass(ModuleNotFoundError, ImportError)True
Em particular, o Python resolve o
ModuleNotFoundErrorif the module (for example
Cryptography) can not be found. If it can be found, there may be a problem loading the module or certain files within the module. In these cases, Python would throw a
If an import statement fails to import a module, it will trigger an
ImportError. This could be due to an incorrect installation or an invalid path. InPython 3.6 or newer, this will generally increase a
The following video shows how to solve the problem
The video below shows how to do it.Import a role from another folder– Making mistakes often leads to
How to fix "ModuleNotFoundError: No module named 'encryption'" in PyCharm
When you create a new Python project inPyCharmGenericNameand try to import it
Cryptographylibrary, the following error message is thrown:
Traceback (last call): File "C:/Users/.../main.py", line 1, in <module> import cryptographyModuleNotFoundError: No module named 'cryptography'Process completed with exit code 1
The reason for this is that by default every PyCharm project has avirtual environmentwhere you can install custom Python modules. But the virtual environment is initially empty - even if you already have it installed
Cryptographyin your computer!
Here is a screenshot that illustrates this.
pandasLibrary. will be similar to
The solution is simple: use thePyCharm-InstallationTool tips for installing pandas in your virtual environment - two clicks and done!
First, right-click on the
pandasText in your editor:
Second, click "
Show context actions' in your context menu. In the new menu that appears, click "Install Pandas" and wait for PyCharm to complete the installation.
The code will run after the installation completes successfully.
Alternatively, you can also open the
terminaltool below and type:
Install $pip encryption
If that doesn't work, you can set the Python interpreter to a different version using the following tutorial:https://www.jetbrains.com/help/pycharm/2016.1/configuring-python-interpreter-for-a-project.html
You can also install a new library manually, for example
Cryptographyin PyCharm using the following procedure:
File > Settings > Projectno menu PyCharm.
- Select your current project.
Python-InterpreterTab within your project's tab.
- Click on the small
+Icon for adding a new library to the project.
- Now enter the library to install, Pandas in your example, and click
- Wait for the installation to complete and close all pop-up windows.
Here is an analog example:
Here is a complete guide on how to install a library in PyCharm.
- How to install a library in PyCharm
❓To ask: Why do programmers always confuse Halloween and Christmas?
❗Responder: Because October 31 is the same as December 25.
(If you don't understand this, read our articles onOctober ()Eint()Python built-in functions!)
During his work as a researcher in the field of distributed systems,Dr. Christian Mayerdiscovered his love of teaching computer science students.
To help students reach a higher level of success in Python, he founded the Programming Education websiteFinxter.com. He is the author of the popular programming bookPython dialogs(NoStarch 2020), co-author desPython coffee breakSelf-published book series, computer science enthusiast,freelancer, and owner of one of the 10 largestPython-Blogsworldwide.
His passions are writing, reading and programming. But his greatest passion is serving and helping aspiring programmers improve their skills through Finxter. You canJoin your free email academy here.