Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenv python broke after upgrading ubuntu 15.10 to 16.04

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?

like image 602
Александр Котовский Avatar asked Apr 22 '16 14:04

Александр Котовский


1 Answers

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

like image 150
ed. Avatar answered Oct 02 '22 15:10

ed.