Python3 not working in Ubuntu after accidetaly deleting usr/lib/ files - python

I'm using Ubuntu 16.04 LTS, I recently accidentaly deleted some files and folders
( /urs/lib/pyhon3.x ), after this Python3 is not working.
python3 gives the following error message.
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 0x00007f7e77307700 (most recent call first):
Aborted (core dumped)
I have tried re-installing python3 by
sudo apt-get install python3
Still, the problem persists, I have tried unset PYTHONHOME and unset PYTHONPATH.
But nothing is working, how can we make this work?
Update(1) pip is not working as python is not working.
pip install encodings returns the following error,
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 0x00007f76e2667700 (most recent call first):
Aborted (core dumped
Update (2) :
I have tried
sudo apt-get --purge autoremove python3 then rebooot then, sudo apt install python3,
it gives the following error,
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3 is already the newest version (3.5.1-3).
0 upgraded, 0 newly installed, 0 to remove and 54 not upgraded.
2 not fully installed or removed.
Need to get 0 B/8 710 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
[master ccedc09] saving uncommitted changes in /etc prior to apt run
Author: rajgourav <rajgourav#euclide.ipcms1.ipcms.unistra.fr>
8 files changed, 4 insertions(+), 4 deletions(-)
Setting up python3.5 (3.5.2-2ubuntu0~16.04.12) ...
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'
Current thread 0x00007efddc85f700 (most recent call first):
Aborted (core dumped)
dpkg: error processing package python3.5 (--configure):
subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3:
python3 depends on python3.5 (>= 3.5.1-2~); however:
Package python3.5 is not configured yet.
dpkg: error processing package python3 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
Errors were encountered while processing:
python3.5
python3

I removed python3 from my ubuntu(18.0.4.5) to see if i can reproduce
the same problem.
It seems that removing python and configuration files by
sudo apt-get --purge autoremove python3
sudo reboot
then
sudo apt install python3
works

Have you tried to install the module encodings with pip install encodings ?
Else, try to reconfigure Python3 with dpkg using the command sudo dpkg-reconfigure python3

Related

Installation Failure in python

I had a problem trying to install TensorFlow. After multiple unsuccessful attempts, I uninstalled everything related to python.
Now, when I try to install python with
pip install python
I got the following error related to the path:
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 load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fffa1d233c0 (most recent call first):
Abort trap: 6
Probably you can't install Python via pip, because you may have deleted pip together with Python. Try to install Python from the official Python website: https://www.python.org/downloads/

python unistallation gone wrong, apt-get and dpkg broken error message 1 on Ubuntu

The title says it all in short. I tried to purge all of my python installations as they were a mess. Turned out I broke everything and was not able to install or uninstall anything with apt-get or dpkg, only got the following error message (or similar) various times:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libexpat1-dev libpython3.7 libpython3.7-dev libpython3.7-minimal libpython3.7-stdlib libpython3.8
libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib zlib1g-dev
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
python3
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 191 kB disk space will be freed.
Do you want to continue? [Y/n] Y
dpkg: error processing package python3 (--remove):
package is in a very bad inconsistent state; you should
reinstall it before attempting a removal
Errors were encountered while processing:
python3
E: Sub-process /usr/bin/dpkg returned an error code (1)
What sudo dpkg --audit currently gives me is:
sudo dpkg --audit
The following packages are only half configured, probably due to problems
configuring them the first time. The configuration should be retried using
dpkg --configure <package> or the configure menu option in dselect:
python3-lib2to3 Interactive high-level object-oriented language (2to3, ve
python3-minimal minimal subset of the Python language (default python3 ve
The following packages are missing the list control file in the
database, they need to be reinstalled:
libpython3-stdlib:amd64 interactive high-level object-oriented language (default
libpython3.6:amd64 Shared Python runtime library (version 3.6)
libpython3.6-minimal:amd64 Minimal subset of the Python language (version 3.6)
libpython3.6-stdlib:amd64 Interactive high-level object-oriented language (standard
libpython3.7:amd64 Shared Python runtime library (version 3.7)
libpython3.7-dev:amd64 Header files and a static library for Python (v3.7)
libpython3.7-minimal:amd64 Minimal subset of the Python language (version 3.7)
libpython3.7-stdlib:amd64 Interactive high-level object-oriented language (standard
libpython3.8:amd64 Shared Python runtime library (version 3.8)
libpython3.8-dev:amd64 Header files and a static library for Python (v3.8)
libpython3.8-minimal:amd64 Minimal subset of the Python language (version 3.8)
libpython3.8-stdlib:amd64 Interactive high-level object-oriented language (standard
python3.6 Interactive high-level object-oriented language (version
python3.6-minimal Minimal subset of the Python language (version 3.6)
The following packages are missing the md5sums control file in the
database, they need to be reinstalled:
libpython3-stdlib:amd64 interactive high-level object-oriented language (default
libpython3.6:amd64 Shared Python runtime library (version 3.6)
libpython3.6-minimal:amd64 Minimal subset of the Python language (version 3.6)
libpython3.6-stdlib:amd64 Interactive high-level object-oriented language (standard
libpython3.7:amd64 Shared Python runtime library (version 3.7)
libpython3.7-dev:amd64 Header files and a static library for Python (v3.7)
libpython3.7-minimal:amd64 Minimal subset of the Python language (version 3.7)
libpython3.7-stdlib:amd64 Interactive high-level object-oriented language (standard
libpython3.8:amd64 Shared Python runtime library (version 3.8)
libpython3.8-dev:amd64 Header files and a static library for Python (v3.8)
libpython3.8-minimal:amd64 Minimal subset of the Python language (version 3.8)
libpython3.8-stdlib:amd64 Interactive high-level object-oriented language (standard
python3.6 Interactive high-level object-oriented language (version
python3.6-minimal Minimal subset of the Python language (version 3.6)
Using sudo dpkg --configure on both python3-minimal and python3-lib2to3 gives me the following:
Setting up python3-minimal (3.6.7-1~18.04) ...
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
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fa5074f0740 (most recent call first):
Aborted (core dumped)
dpkg: error processing package python3-minimal (--configure):
installed python3-minimal package post-installation script subprocess returned error exit status 134
Errors were encountered while processing:
python3-minimal
$ sudo dpkg --configure python3-lib2to3
Setting up python3-lib2to3 (3.6.9-1~18.04) ...
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
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f439a7a0740 (most recent call first):
Aborted (core dumped)
dpkg: error processing package python3-lib2to3 (--configure):
installed python3-lib2to3 package post-installation script subprocess returned error exit status 134
Errors were encountered while processing:
python3-lib2to3```
I have tried everything found [here][1], and have no idea what to try next. Anyone run into such a mess of a package removal before?
[1]: https://phoenixnap.com/kb/fix-sub-process-usr-bin-dpkg-returned-error-code-1
Have you tried --remove --force ?

Install virtual environment fails on Ubuntu16.4

I am trying to install virtual environment on my Ubuntu and my python is 3.5. My command is:
python3 -m venv my-env/
It reminds me to install python3-venv first, but then got the following error.
apt-get install python3-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-venv is already the newest version (3.5.1-3).
0 upgraded, 0 newly installed, 0 to remove and 95 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
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Setting up cython3 (0.23.4-0ubuntu5) ...
Traceback (most recent call last):
File "/usr/bin/py3compile", line 34, in <module>
from debpython.version import SUPPORTED, debsorted, vrepr, \
ImportError: No module named 'debpython'
dpkg: error processing package cython3 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
cython3
E: Sub-process /usr/bin/dpkg returned an error code (1)
Is this because Python3.5 doesn't work with python3 -m venv? If I can't upgrade python3.5, what can I do?
You can't use apt-get install without root/sudo. Yeah you can jump through hoops but ignoring that.
You can use anaconda-python without root. That would be a separate python from the system one with likely a different version. And that's a subject for another question
Your locales are messed up
Yeah the error mesg could be better
Added later
Why venv is absent from builtin-python I'm not clear; it's supposed to be there 3.3 onwards
Pip is alternative to apt and by default works for user — sudo not required.
You can get pip by hand but it's fiddly and ill-advised
However the pip module should work even if the command is not available ie use
python3 -m pip where you were using just pip

Cannot uninstall python/pip on raspberry pi 3 b+

I am working on a raspberry pi 3B+. I want to upgrade the python from 2.7 to 3.6.
I downloaded the python 3.6 extracted and made it, However it got installed in the /usr/local/bin.
I tried to make it again this time by specifying ./configure --prefix=/usr prefix however the make gave a traceback error.
I also tried update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2 which helps in changing versions of python.
However, after doing so, my pip is not working now.
I have the following files in /usr/local/bin:pip,pip2.7,pip3,pip3.5,pip3.6.
I tried removing pip so that i can reinstall it using sudo apt-get remove python-pip but it gives the following error:
pi#raspberrypi:/usr/local/bin $ sudo apt-get remove python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libpython-all-dev python-all python-all-dev python-keyring
python-keyrings.alt python-secretstorage python-wheel
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
python-pip
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
1 not fully installed or removed.
After this operation, 671 kB disk space will be freed.
Do you want to continue? [Y/n] y
Traceback (most recent call last):
File "/usr/bin/apt-listchanges", line 29, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
(Reading database ... 138007 files and directories currently installed.)
Removing python-pip (9.0.1-2+rpt2) ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
^
SyntaxError: invalid syntax
dpkg: error processing package python-pip (--remove):
subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 35, in <module>
from debpython.version import SUPPORTED, debsorted, vrepr, \
File "/usr/share/python/debpython/version.py", line 24, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)
which suggests that apt_pkg (or some problem with apt-get).
when i do pip --version , i get:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
I just want to have python 3.6 and 2.7(since i have already installed libraries on 2.7) with functional pip.
Why don't you install miniconda for ARM and get Python and all important packages at once ?
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
sudo md5sum Miniconda3-latest-Linux-armv7l.sh
sudo /bin/bash Miniconda3-latest-Linux-armv7l.sh
sudo reboot -h now
I think you aren't aware that most linux distros come shipped with python2 AND python3. By typing python and pip you will use your operating systems python2 and pip2 version.
What you probably want is using python3 and pip3 instead.
Something like "upgrading" from python2 to python3 is not possible because it's a fundamental difference and they are incompatible. This is why you have both installed.
Uninstalling or upgrading your systems python interpreter is a terrible bad idea, because your system needs them. For professional usage you should think about version control again, but for your first (and second) steps in python it's totally fine to use the preinstalled python interpreter of your OS.
Solutions like pyenv or virtualenv are very powerfull tools, but you probably don't want to start with it.

Repair damaged Python3.2 installation (Ubuntu)

I stupidly removed the subprocess.py module from /usr/lib/python3.2 so I tried to fix this by executing the following command:
sudo apt-get install python3
But I got this error:
Traceback (most recent call last):
File "/usr/bin/py3compile", line 33, in <module>
from subprocess import PIPE, Popen ImportError:
No module named subprocess dpkg:
error processing python3 (--configure):
subprocess installed post-installation script returned error exit status 1 dpkg:
dependency problems prevent configuration of python3-gobject:
python3-gobject depends on python3 (>= 3.2); however:
Package python3 is not configured yet. python3-gobject depends on python3 (<<
3.3); however:
Package python3 is not configured yet. dpkg: error processing python3-gobject (--configure):
dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
python3 python3-gobject E: Sub-process /usr/bin/dpkg returned an error code (1)
How can I fix this?
Have you tried uninstalling Python 3 and then installing it again?
sudo apt-get remove python3
sudo apt-get install python3
or maybe
sudo apt-get --reinstall install python3
If this does not work, just grab subprocess.py from the python repository and copy it to the right directory. For example, for Python 3.2.2, navigate with your browser to:
http://hg.python.org/cpython/file/137e45f15c0b/Lib/subprocess.py
and the click in "raw" (left column) to download the file.
For other versions, just go to:
http://hg.python.org/cpython/tags
Pick your version, then click on browse (left column), then Lib (from the folders list), then "subprocess.py" and then "raw" (left column) to download the file.

Categories

Resources