ImportError: No module named 'encodings'

I recently reinstalled ubuntu and did upgrade to 16.04 and cannot use python:

    $ python manage.py runserver
    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Fatal Python error: Py_Initialize: Unable to get the locale encoding
    ImportError: No module named 'encodings'
    Aborted

At this point, python itself doesn't work

    $ python
    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Fatal Python error: Py_Initialize: Unable to get the locale encoding
    ImportError: No module named 'encodings'
    Aborted

Even this suggestion is no longer working:

    unset PYTHONHOME
    unset PYTHONPATH

Every every I fix it one way, it comes back again. Several answers help to fix it temporarily, but not for good. I've reinstalled python and python3 several times. What can I do from here? Thank you

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

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

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

From: stackoverflow.com/q/38132755

Back to homepage or read more recommendations: