No Module named “Encodings” — A common Import Error Found In Python 3

#Python   #softwaredevelopment  
0_QYpZMj_O3ATv7u5W.png

So, recently, I saw that many beginners are encountering this difficulty while installing Python 3 for the first time; in fact, when I installed Python for the first time, I had the same issue. The solution is simple, as we shall see in this article.

The Problem!

So, when we install Python 3, we usually do skip and next without selecting any options. When we install Python, we get the “Add To Path” option; if we ignore this option, we get this error in Python.
The scenario differs depending on the type of operating system.
The resulting error for Windows looks like this:

1.png

The resulting error for Linux looks like this:

2.png

Possible things that could raise this error?

  1. Broken packages
    2. Version update
    3. Unmet dependencies
    4.Reinstalltion of Python

The Solution!

For Windows Users Steps are:

  1. When you download Python3.x and run .exe file, you will be given the option to select where you want Python to be installed. For example, I chose this location: C:\Program Files\ Python36
  2. Then, open system properties and navigate to the “Advanced” tab. (Thus, you may simply do this: Go to Start > Type “environment variables” into the search box > Select “Edit the system environment variables.”) Look for “Environment Variables” under the “Advanced” tab and click it. A new window with the title “Environment Variables” will appear.
  3. Ensure that the Python path for your user variables is shown in “Path Variable.” You should see C:\Program Files\Python36. If it isn’t available, add it by choosing the Path Variable box and clicking Edit.
  4. The next step is to double-check the PYTHONHOME and PYTHONPATH entries in the same window’s System Variables. The path mentioned above should be visible to you. If not, include it there as well.

Then click OK to go to the CMD terminal and check for python. The error should now be resolved.

For Linux Users:
Setting path in linux is different it depends on the shell you are currently using. For different shells it will be like this:
a). In the csh shell −

type setenv PATH "$PATH:/usr/local/bin/python3" and press Enter.

b). In the bash shell (Linux) −

type export PYTHONPATH=/usr/local/bin/python3.x and press Enter.

c). In the sh or ksh shell −

type PATH = "$PATH:/usr/local/bin/python3" and press Enter.

Note − /usr/local/bin/python3 is the path of the Python directory.

Other Solution

For ImportError : No module named ‘encodings’ in a virtual environment:
The Error Should look like this:

3.jpeg

You Just need to remove virtual environment files. Follow this command.

rm -rf venv
virtualenv -p /usr/bin/python3 venv/
source venv/bin/active
pip install -r requirements.txt

Conclusion

It is all about this issue. I hope this is found useful for you guys. Let me know if you have any queries regarding this, Thank You.

Start blogging about your favorite technologies and get more readers

Join other developers and claim your FAUN account now!

Discussed tools
Python