ImportError: No module named ‘encodings’: Amazing Tricks To Fix

Python is a well-known programming language in the world. It is famous for its usability and readability. 

Nevertheless, there are times when you might run into an error that is difficult to solve. One such error is ImportError: No module named ‘encodings.’ This article will show you how to solve this error.

How Did This Error Occur?

While you are working with Python, a message suddenly appears:

ImportError: No module named 'encodings'

This error happens explicitly when the system cannot find the encoding module. Python’s encoding module is necessary to convert text from one format to another. 

The file containing the encoding module has been moved, renamed, or deleted when this error occurs. 

You can read our methods in the following sections to fix this error. Keep reading to discover!

2 Amazing Solutions For The ImportError: No module named ‘encodings.’ Issue

Solution 1

The first solution is to remove virtual environment files. To do this, you can read our instructions here. 

Step 1:  First, we need to identify the location of the virtual environment files. To do this, we can use the “ls” command. We can see that the virtual environment is located in the “/Users/USERNAME/virtualenvs/ENVIRONMENT_NAME/” folder.

Step 2: You need to remove the directory that contains the Python virtual environment files (venv). To do this, run the following command: 
rm -rf venv

Step 3: Create a new virtual environment: 

virtualenv -p /usr/bin/python3 venv/

Step 4: Run this line: source venv/bin/activate 

This command will activate the virtual environment. All the commands will be conducted in the virtual environment.

Step 5: Lastly, you can use the below content to complete the fixing process:

pip install -r requirements.txt

This command will install all the demanded packages for this project.

Solution 2

The second method is to update the PATH value in the environment variables by following the steps below:

Step 1: Open up System Preferences by clicking the Apple logo in the top-left corner of your screen and selecting “System Preferences”.

Step 2: Click on “Advanced” and select the “Environment Variables” button.

Step 3: Under “User Variables”, find the variable named “PATH”. It will have a value that looks something like this: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin .

Step 4: Add the following to the end of that value, separated by a semicolon (;): /Library/Frameworks/Python.framework/Versions/3.6/bin.

Step 5. Click “OK” to save your changes 


In conclusion, the ImportError: No module named ‘encodings’ error can occur for various reasons. However, you can usually fix the problem quickly by troubleshooting the issue and understanding the underlying cause.

If you continue to deal with this error or cannot fix it on your own, be sure to ask a professor for help.

Related articles
Scroll to Top