I'm in a bit of a python death spiral, here, with the "ImportError: No module named encodings" error when I try using python. I've read a dozen or so different posts on the problem, and none of them help. Advice welcome (please be specific, since I'm a bit of a novice).
The original install was done as part of an OpenCV installation here. I was able to use the virtual environment and do everything I needed to do. Then this morning I picked up the RPi again and did an update/upgrade. Now, when I log on (or source .profile), I get:
pi@raspberrypi:~ $ source .profile
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'
Current thread 0x76f06010 (most recent call first):
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is
set properly.
I can run python2.7, but attempting to import locale give a similar error:
pi@raspberrypi:~ $ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/locale.py", line 13, in <module>
import encodings
ImportError: No module named encodings
>>>
python3 won't run at all:
pi@raspberrypi:~ $ python3
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'
Current thread 0x76f91010 (most recent call first):
Aborted
Some threads suggest setting $PYTHONHOME and $PYTHONPATH; others say not to (that's the point of the virtual environment). I've tried setting them -- though I'm not 100% sure of what to set them to -- but the outputs above are with them unset. I have set:
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
and the path is:
pi@raspberrypi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
This thread suggests rebuilding the virtual environment, but that just gives me the same errors:
pi@raspberrypi:~ $ rm -rf venv
pi@raspberrypi:~ $ virtualenv -p /use/bin/python3/ venv/
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'
Current thread 0x76fd3010 (most recent call first):
Aborted
Suggestions for what to try next? I'm hoping it's just an env setting that I've screwed up, but I can't figure it out.
It took a long time to get OpenCV up and running -- I'd hate to have to redo all of that.