Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find platform independent libraries <prefix>

Tags:

python

conda

My travis job hit issue of following:

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

I have already tried to set PYTHONPATH and PYTHONHOME, but still doesn't work. Could anyone help me on that ? Thanks

export PYTHONHOME='$HOME/miniconda'
export PYTHONPATH='$HOME/miniconda:$PYTHONPATH'
like image 349
zjffdu Avatar asked Jul 09 '17 01:07

zjffdu


1 Answers

This happens when you remove the default python libraries and don't replace it. For example when following upgrade instructions that are less than complete. I ran into this and solved it like this on ubuntu ( should be similar process on others )...

I installed new python using ( overuse of sudo I know ):

$ sudo apt-get update
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

$ cd /usr/src
$ sudo wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz

$ sudo tar xzf Python-2.7.13.tgz
$ cd Python-2.7.13
$ sudo ./configure
$ sudo make install

This created a python2.7 for me in /usr/local/lib and /usr/local/bin. I then deleted the system python in /usr/lib/ thinking I don't want two versions and things broke. Because the new python is in /usr/lib/local and the system is looking in /usr/lib/.

$ cd /usr/lib
$ sudo rm -rf python2.7

The specific error I got after deleting system python libraries was:

$ sudo apt-get install python-httplib2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-httplib2 is already the newest version (0.8-2build1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python-httplib2 (0.8-2build1) ...
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site
dpkg: error processing package python-httplib2 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 python-httplib2
E: Sub-process /usr/bin/dpkg returned an error code (1)

To fix this replace the system python with your newly installed python ( I did the first two earlier but I want to show a proper python swap here ):

$ cd /usr/lib
$ sudo rm -rf python2.7
$ sudo ln -s /usr/local/lib/python2.7 python2.7

$ cd /usr/bin
$ sudo rm python2.7
$ sudo ln -s /usr/local/bin/python python2.7

Then things work again...

$ sudo apt-get install python-httplib2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-httplib2 is already the newest version (0.8-2build1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python-httplib2 (0.8-2build1) ...
like image 180
Paul Kenjora Avatar answered Oct 29 '22 15:10

Paul Kenjora