Issue
I am using Ubuntu 14.04
I wanted to install package "requests" to use in python 3.5, so I installed it using pip3. I could see it in /usr/lib/python3.4, but while trying to actually execute scripts with Python 3.5 I always got "ImportError: No module named 'requests'"
OK, so I figured, perhaps that's because the package is not in python3.5 but in python3.4. Therefore, I tried to uninstall and install i again, but it just kept popping up where I didn't want it (not to mention, when I run apt-get remove pip3-requests, it actually removed pip3 for me as well lol). Therefore, I tried physically removing python3.4 from usr/lib and usr/local/lib in order to try and see if maybe pip3 was confused and installed packages in wrong directories.
I'm afraid it was not a good idea... when I now run e.g.
sudo pip3 install reqests
I get the following error:
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Is there any way to fix this now? And to actually use requests package?
When I use
sudo apt-get install python3-pip
It works and starts unpacking etc. but then I get a long error that starts with:
Setting up python3.4 (3.4.3-1ubuntu1~14.04.3)
Could not find platform independent libraries <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
dpkg: error processing package python3.4 (--configure):
subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3:
(...) and ends with
python3 depends on python3.4 (>= 3.4.0-0~); however:
Package python3.4 is not configured yet.
dpkg: error processing package python3-wheel (--configure):
dependency problems - leaving unconfigured
E: Sub-process /usr/bin/dpkg returned an error code (1)
Solution
First of all, it is a very bad idea to remove your system Python 3 in Ubuntu (which 3.4 is in recent
subrevisions of Trusty LTS). That is because it is a vital part of the system. If you run the command apt-cache rdepends python3
, you'd see that packages such as ubuntu-minimal
, ubuntu-release-upgrader-core
, lsb-release
, lsb-core
, ubuntu-core-libs
and so on, all depend on Ubuntu's version of Python 3 being installed (and this is the python3.4 in Ubuntu 14.04.4). If you force-remove python 3.4 by hand, you've ruined your system.
It might very well be
that you now have to reinstall the whole operating system, unless you manage to reinstall all the system
.deb
packages that put data in /usr/lib/python3.4
.
And especially so if you do it with force. It can make your system even unbootable, so do not reboot that computer before you've successfully reinstalled Python 3... actually I am not sure how to do it safely since it seems you've forcefully removed all system dependencies from the /usr/lib)
You should try to reinstall python3.4
sudo apt-get install --reinstall python3.4
But now the bigger problem is that you've still missing all sorts of dependencies for your system programs.
Do note that pip
also should be available as a module. Thus to ensure that you install for Python 3.5,
you can do
sudo python3.5 -mpip install requests
The pip3
is a wrapper for a pip
that installs to the system Python 3 version (3.4 in your case).
Answered By - Antti Haapala