2

My system is Ubuntu 16.04.

~$ python3 -V
Python 3.6.5 :: Anaconda, Inc.
~$ python -V
Python 3.6.5 :: Anaconda, Inc.

I once did some stupid thing about rm -f to remove some lower version of python according to this. Then I got many unsolvable errors.

What I have installed:

~$ whereis python
python: /usr/bin/python3.5 /usr/bin/python3.5m /usr/lib/python2.7 /usr/lib/python3.5 /etc/python3.6 /etc/python2.7 /usr/local/lib/python2.7 /usr/local/lib/python3.5 /home/wxf/anaconda3/bin/python3.6 /home/wxf/anaconda3/bin/python3.6-config /home/wxf/anaconda3/bin/python3.6m-config /home/wxf/anaconda3/bin/python /home/wxf/anaconda3/bin/python3.6m

The errors I have when I install some packages, for example:

sudo apt install devscripts

The output:

~$ sudo apt install devscripts
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 devscripts : Depends: python3:any (>= 3.3.2-2~)
              Recommends: dctrl-tools
              Recommends: dput or
                          dupload but it is not going to be installed
              Recommends: libdistro-info-perl but it is not going to be installed
              Recommends: lintian but it is not going to be installed
              Recommends: patchutils
              Recommends: python3-debian (>= 0.1.15) but it is not going to be installed
              Recommends: python3-magic but it is not going to be installed
              Recommends: wdiff but it is not going to be installed
 dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

I try to remove all python but I still get the same dependency errors.

If I do apt-get -f install xxxx

~$ sudo apt-get -f install python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  python3-doc python3-tk python3-venv
The following NEW packages will be installed:
  python3
0 upgraded, 1 newly installed, 0 to remove and 53 not upgraded.
4 not fully installed or removed.
Need to get 0 B/8,710 B of archives.
After this operation, 68.6 kB of additional disk space will be used.
Setting up python3.5-minimal (3.5.2-2ubuntu0~16.04.4) ...
# Empty sitecustomize.py to avoid a dangling symlink
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 0x00007f29be846700 (most recent call first):
Aborted
dpkg: error processing package python3.5-minimal (--configure):
 subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3-minimal:
 python3-minimal depends on python3.5-minimal (>= 3.5.1-2~); however:
  Package python3.5-minimal is not configured yet.

dpkg: error processing package python3-minimal (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python3.5-minimal
 python3-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

or without package name

~$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  python3
Suggested packages:
  python3-doc python3-tk python3-venv
The following NEW packages will be installed:
  python3
0 upgraded, 1 newly installed, 0 to remove and 53 not upgraded.
4 not fully installed or removed.
Need to get 0 B/8,710 B of archives.
After this operation, 68.6 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python3.5-minimal (3.5.2-2ubuntu0~16.04.4) ...
# Empty sitecustomize.py to avoid a dangling symlink
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 0x00007fc90fdb7700 (most recent call first):
Aborted
dpkg: error processing package python3.5-minimal (--configure):
 subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3-minimal:
 python3-minimal depends on python3.5-minimal (>= 3.5.1-2~); however:
  Package python3.5-minimal is not configured yet.

dpkg: error processing package python3-minimal (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python3.5-minimal
 python3-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

The dependency problem recursively occurs

~$ sudo apt-get -f install python3.5-minimal
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.5-minimal is already the newest version (3.5.2-2ubuntu0~16.04.4).
python3.5-minimal set to manually installed.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
skytree
  • 1,060
  • 2
  • 13
  • 38
  • 1
    It has been clearly indicated in the message, try `apt-get -f install` – Milo Lu Oct 17 '18 at 01:26
  • @MiloLu It doesn't solve my problem. I have already installed `python3-minimal` and `python3.5-minimal`. Even so, it still shows the dependency issues. – skytree Oct 17 '18 at 01:29
  • `apt-get -f install`, with no packages – Milo Lu Oct 17 '18 at 01:34
  • @MiloLu Sorry, it doesn't work at all. – skytree Oct 17 '18 at 01:38
  • what is the output of `which python`. Try reinstalling python3 with the -no-install-recommends flag. Related: https://stackoverflow.com/questions/38132755/importerror-no-module-named-encodings – Rahul Shah Oct 17 '18 at 01:43
  • @RahulShah Hi, the output is `/home/wxf/anaconda3/bin/python` . I tried reinstalling with -no-install-recommends flag. But it doesn't work. – skytree Oct 17 '18 at 01:47
  • 1
    This question should actually be asked on [`ask ubuntu`](https://askubuntu.com) or similar sites, not here. You really messed this up by removing system installed packages in such a manner. System packages very likely depend on each other and so should be uninstalled using the system's package manager. Try [this](https://docs.python-guide.org/starting/install3/linux/) to see if it works for you – smac89 Oct 17 '18 at 01:48
  • @smac89 Sorry, it doesn't work. Does that mean I need to reinstall Ubuntu system on my server because of python problem? Thanks. – skytree Oct 17 '18 at 01:51
  • There are manual ways to install python. Including building from source. See [`this answer`](https://unix.stackexchange.com/a/332658/44793) on unix exchange – smac89 Oct 17 '18 at 01:55

0 Answers0