I had python 3.4 in my virtualenv, but after upgrading ubuntu to 16.04 python upgraded to 3.5 so python in virtualenv crashes with these errors:
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 0x00007f2f2dbcb700 (most recent call first):
fish: “python” terminated by signal SIGABRT (Abort)
How can i fix it?
I fixed this by installing the minimum working python3.4 so that my virtualenv worked well enough to get the list of packages, then made a new one with python3.5... as follows:
Get python3.4 minimal packages:
wget http://launchpadlibrarian.net/221250032/python3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
wget http://launchpadlibrarian.net/221250033/libpython3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
sudo dpkg -i --force-breaks libpython3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
sudo dpkg -i python3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb
My virtualenv is here: ~/virtualenv/example
Get the list of packages in your virtualenv (which should now work well enough for this, but might not do other things properly):
source ~/virtualenv/example/bin/activate
pip freeze > /tmp/requirements.txt
deactivate
Get rid of python3.4, to return to Ubuntu 16.04's preferred state:
sudo dpkg --purge python3.4-minimal
sudo dpkg --force-depends --purge libpython3.4-minimal
Make a new virtualenv with the right packages:
virtualenv -p python3.5 example
source ~/virtualenv/example/bin/activate
pip install -r /tmp/requirements.txt
That should now work, with all your old packages but in python3.5. Should...
See also Upgrade python in a virtualenv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With