ImportError: No module named 'encodings'

codyc4321 picture codyc4321 · Jun 30, 2016 · Viewed 219.6k times · Source

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

Answer

Anoop Malav picture Anoop Malav · Aug 23, 2016

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