1

I lately installed python 3.5 from the source, but I think I did something wrong during the installation or linking. After this I have problem installing any Ubuntu packages. For example, add-apt-repository doesn't work, even after reinstalling software-properties-common.

$ add-apt-repository 
bash: /usr/bin/add-apt-repository: /usr/bin/python3: bad interpreter: No such file or directory

Also, apt-get install will give me this errors

$ sudo apt-get install libraw-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libraw-dev
0 upgraded, 1 newly installed, 0 to remove and 229 not upgraded.
3 not fully installed or removed.
Need to get 382 kB/391 kB of archives.
After this operation, 1,588 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main libraw-dev amd64 0.15.4-1 [382 kB]
Fetched 382 kB in 0s (651 kB/s)    
Selecting previously unselected package libraw-dev:amd64.
(Reading database ... 295477 files and directories currently installed.)
Preparing to unpack .../libraw-dev_0.15.4-1_amd64.deb ...
Unpacking libraw-dev:amd64 (0.15.4-1) ...
Setting up python3.4 (3.4.3-1ubuntu1~14.04.5) ...
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
Setting up python3-commandnotfound (0.3ubuntu12) ...
/var/lib/dpkg/info/python3-commandnotfound.postinst: 6: /var/lib/dpkg/info/python3-commandnotfound.postinst: py3compile: not found
dpkg: error processing package python3-commandnotfound (--configure):
 subprocess installed post-installation script returned error exit status 127
dpkg: error processing package software-properties-common (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Setting up libraw-dev:amd64 (0.15.4-1) ...
Errors were encountered while processing:
 python3.4
 python3-commandnotfound
 software-properties-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

Also, trying to add ppa gives the following error

$ sudo add-apt-repository ppa:dhor/myway
sudo: unable to execute /usr/bin/add-apt-repository: No such file or directory

What's going on, any ideas?

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • 2
    What is the output of ls -l /usr/bin/python3 ? and whereis python3? – Ravexina May 12 '17 at 18:12
  • It gives: ls: cannot access /usr/bin/python3: No such file or directory I don't think python3 exists. – user109352 May 12 '17 at 18:34
  • 1
    what about this command : whereis python3 – Ravexina May 12 '17 at 19:05
  • 2
    And this, dear children, is exactly why you don't mess with the Python. – Byte Commander May 12 '17 at 19:42
  • it gives python3: /usr/bin/python3.4 /usr/bin/python3.4m /etc/python3.5 /etc/python3.4 /etc/python3 /usr/lib/python3.4 /usr/lib/python3 /usr/bin/X11/python3.4 /usr/bin/X11/python3.4m /usr/local/bin/python3.5m-config /usr/local/bin/python3.5 /usr/local/bin/python3.5-config /usr/local/bin/python3 /usr/local/bin/python3.5m /usr/local/lib/python3.5 /usr/share/python3 /usr/share/man/man1/python3.1.gz – user109352 May 12 '17 at 21:30

2 Answers2

1
  1. First, you need to restore the core of Python 3:

    sudo apt install -f --reinstall python3 python3.4 python3-minimal python3.4-minimal libpython3.4-minimal
    

    If this doesn't work due to half-installed packages depending on Python 3 download and install them manually:

    cd /tmp
    apt-get download python3 python3.4 python3-minimal python3.4-minimal libpython3.4-minimal
    sudo dpkg -i *python3*.deb
    sudo apt install -f
    
  2. Install the debsums package and perform a package sanity check to verify the integrity of the remaining packages and reinstall them if necessary.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
0

Ubuntu ships with its own installations of Python that it depends on in order for system utilities to work. These utilities rely on python, python2, and python3 pointing to these system installations. Unfortunately, when building/installing Python from source, the standard make install installs new python/python2 (for Python 2.x) or python3 (for Python 3.x) binaries, which can end up shadowing the system Python installations and breaking things.

Once you have your system fixed (David's answer should hopefully get you going on that), your compiled-from-source Python should then be (re)installed with make altinstall, which will forgo python3 and install the interpreter only as the version-specific python3.5. This is the safe way to install your own Python without interfering with the system Pythons, as it will not shadow any of the commands relied upon by system utilities.

jcgoble3
  • 143
  • 5