Importerror: No Module Named 'Encodings'

ImportError: No module named 'encodings'

For Python-3 try removing virtual environment files. And resetting it up.

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

https://wiki.ubuntu.com/XenialXerus/ReleaseNotes#Python_3
edit fo

No module named 'encodings' on OpenSuse

Looking at the strace output for both root and greg, the problem seems clear.

For the root user, python 3.6 finds the libraries in /usr/lib64/python3.6.

However, for greg, it only looks under /usr/bin/python3 for subdirectories. That doesn't work because /usr/bin/python3 is a file.

I suspect that the user greg has PYTOHNHOME set erroneously to the location of the Python binary , and that is causing the issue.

Remove PYTOHNHOME from your environment, log out and log in again.

Note: the stuff below is probably barking up the wrong tree. I'll leave it for information.


The encodings module is an (undocumented) part of the python standard library. It is used by the locale module.

Based on the output I suspect that your Python installation has been damaged or corrupted. Try re-installing python.

EDIT:

If a forced re-install doesn't fix the problem, check that the directory encodings exist in your Python stdlib directory, and is accessible for all users.

To find out which directory that is:

python
>>> import sysconfig
>>> sysconfig.get_path('stdlib')
'/usr/local/lib/python3.9'

Check accessability:

ls -ld /usr/local/lib/python3.9/encodings
drwxr-xr-x 3 root wheel 5632 Dec 11 14:34 /usr/local/lib/python3.9/encodings/

Read and execute for all users, so that is OK.

EDIT2:

Looking at the trace results.

I don't think the missing files are something to worry about. That's just Python looking for the different locations/names that files can have, given that Python is a multiplatform program.

The interesting bit is near the end:

stat("/usr/lib64/python3.6/encodings/__init__.py", {st_mode=S_IFREG|0644, st_size=5642, ...}) = 0
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f78043ae000

This shows that it can find the directory, and map __init__.py into memory.

EDIT3:

Since both Python 2.7 and 3.6 are end-of-life now, I would suggest removing them, and install python 3.10 instead.

EDIT4:

The directory structure is determined by how you install Python. WRT permissions, directories usually have permissions 0755 and files 0644. Traditionally on UNIX, files in /usr/ are owned by root, while the group differs among systems.
The last number (permission for "others" being neither the owner nor the group) are probably most relevant.

You can fix permissions with a combination of find and chmod. For example:

find /usr/lib64/python3.6 -type d -exec chmod 755 {} \;
find /usr/lib64/python3.6 -type f -exec chmod 644 {} \;

should set a good set of permissions for both files and directories in the Python tree.

uwsgi error - ModuleNotFoundError: No module named 'encodings'?

This issue has been addressed here in this thread. If you are running python setup as an administrator or have permanently set PYTHONHOME then this can cause the error.

Undo the necessary action and it should solve your problem.

Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'

I ran into this same issue on Windows 10. Here's how I fixed it:

  1. Open your 'Environment Variables' (Under 'System Properties').
  2. In the window that opens, select the 'Path' row, then click the 'Edit...' button.
  3. There should be two environment variables C:\Python37-32\Scripts\ and C:\Python37-32\ Then click 'OK' (Make sure to check that these path values correspond to the location and version of your Python install.)
  4. Next, in the top portion of the 'Environment Variables' window, look for the PYTHONHOME variable and make sure that it is also set to C:\Python37-32

VS Code: No module named 'encodings'

In the very left corner of VS Code window is a selector of Python version. Don't know why, but it was not selected. VS Code screenshot. You just need to click on it and select Python version.



Related Topics



Leave a reply



Submit