Python 3 が動作しない

Python 3 が動作しない

最近、ソースから Python 3.5 をインストールしましたが、インストールまたはリンク中に何か間違ったことをしたと思います。その後、Ubuntu パッケージのインストールに問題が発生します。たとえば、software-properties-common を再インストールした後でも、add-apt-repository は機能しません。

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

また、apt-get installではこのエラーが発生します

$ 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)

また、PPAを追加しようとすると次のエラーが発生します

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

何が起こっているのか、何か考えはあるか?

答え1

  1. まず、Python 3 のコアを復元する必要があります。

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

    Python 3 に依存するパッケージが半分インストールされていないためにこれが機能しない場合は、手動でダウンロードしてインストールしてください。

    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. パッケージをインストールdebsumsして、パッケージの健全性チェック残りのパッケージの整合性を確認し、必要に応じて再インストールします。

答え2

Ubuntu には、システム ユーティリティが動作するために依存している独自の Python インストールが同梱されています。これらのユーティリティは、これらのシステム インストールを指すpythonpython2python3に依存しています。残念ながら、ソースから Python をビルド/インストールする場合、標準でmake installは新しいpython/ python2(Python 2.x の場合) またはpython3(Python 3.x の場合) バイナリがインストールされ、システムの Python インストールがシャドウイングされ、問題が発生する可能性があります。

システムが修正されたら (David の回答が役に立つはずです)、ソースからコンパイルされた Python を を使用して (再) インストールする必要があります。make altinstallこれにより、 は使用されずpython3、バージョン固有の としてのみインタープリタがインストールされますpython3.5。これは、システム ユーティリティが依存するコマンドを一切シャドウしないため、システムの Python に干渉せずに独自の Python をインストールする安全な方法です。

関連情報