rate this message
Quick Solution:Python raises theImportError: No module named "encryption"
if you can't find the libraryCryptography
. The most common cause of this error is that you have not installed it.Cryptography
expressly withpip install encryption
. Alternatively, you can have otherPython versionson your computer andCryptography
is not installed for the version you are using.
wording of the problem
You've just discovered the amazing features ofCryptography
library and want to try it out, then start your code with the following statement:
import encryption
This is to import the pandas library into your(virtual environment. However, it just throws the followingImportError: 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 thisCryptography
in your standard library. You must install it first!
Before you can import the pandas module, you need to install it using the Python package managerPip
.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 installsCryptography
in your virtual environment on Windows, Linux and MacOS. It is assumed that yourPip
updated 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 installationCryptography
Library. This probably happens becausePip
installed but not in the way you can use. AlthoughPip
may be installed on your system, the script cannot find it. So it is not possible to install the libraryPip
on 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 typingwo Python

step 2: After opening thePython
folder, browse and open thescripts
folder and copy its location. Also make sure that the folder is thePip
File.

stage 3: Now open thescripts
directory at the command prompt with theCD
command and the location you copied earlier.

Step 4: Now install the library withpip install encryption
Command. 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
- O
ModuleNotFoundError
may 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
Cryptography
for Python 3, you might want to give it a trypython3 -m pip install encryption
orInstall Pip3 Encryption
instead ofpip 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
import encryption
Em Python, omatter
The 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
matter
Opinion. 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 betweenImportError
EModuleNotFoundError
?
Python define umerror hierarchy, that is, some error classesyou inheritof other error classes. In our case theModuleNotFoundError
is a subclass ofImportError
Classroom.
You can see it in this screenshot ofDocuments:

You can also check this relationship withistUnterklasse()
built-in function:
>>> issubclass(ModuleNotFoundError, ImportError)True
Em particular, o Python resolve oModuleNotFoundError
if the module (for exampleCryptography
) 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 aImportError
.
If an import statement fails to import a module, it will trigger anImportError
. This could be due to an incorrect installation or an invalid path. InPython 3.6 or newer, this will generally increase aModuleNotFoundError
.
similar videos
The following video shows how to solve the problemImportError
:
How to fix: "ImportError: Unable to import name X" in Python?
The video below shows how to do it.Import a role from another folder– Making mistakes often leads toModuleNotFoundError
:
How to call a function from another file in Python?
How to fix "ModuleNotFoundError: No module named 'encryption'" in PyCharm
When you create a new Python project inPyCharmGenericNameand try to import itCryptography
library, 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 installedCryptography
in your computer!
Here is a screenshot that illustrates this.pandas
Library. will be similar toCryptography
.

The solution is simple: use thePyCharm-InstallationTool tips for installing pandas in your virtual environment - two clicks and done!
First, right-click on thepandas
Text 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 theterminal
tool 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 exampleCryptography
in PyCharm using the following procedure:
- Open
File > Settings > Project
no menu PyCharm. - Select your current project.
- tighten
Python-Interpreter
Tab 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
installation package
. - 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
show humor
❓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!)
cris
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.