Ubuntu

將自編譯的 Python 3.7.0 安裝為“python”,如何刪除它?

  • April 1, 2019

我在我的 Ubuntu 16.04 伺服器上犯了一個巨大的錯誤。

我使用 編譯並安裝了 Python 3.7.0 make altinstall,但我沒有包含我需要的所有核心依賴項,所以我打算刪除它並安裝一個預打包的 deb。

但是,要刪除它,我將此方法與 checkinstall 一起使用。我生成了一個 deb,這樣我就可以刪除原始安裝創建的所有文件,但是對於 deb 的包名,我只保留了預設的python.

現在,我安裝了以下軟體包:

$ sudo dpkg -l python
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                  Version                         Architecture                    Description
+++-=====================================================-===============================-===============================-===============================================================================================================
ri  python                                                3.7.0-1                         amd64                           Package created with checkinstall 1.6.2

這意味著我無法執行dpkg -r python,因為系統包依賴於剛剛呼叫的元包python

$ sudo dpkg -r python
dpkg: dependency problems prevent removal of python:
python-ldb depends on python (<< 2.8).
python-ldb depends on python (>= 2.7~).
python-ldb depends on python (<< 2.8).
python-ldb depends on python (>= 2.7~).
python-ldb depends on python (<< 2.8).
python-ldb depends on python (>= 2.7~).
python-talloc depends on python (<< 2.8).
python-talloc depends on python (>= 2.7~).
python-talloc depends on python (<< 2.8).
python-talloc depends on python (>= 2.7~).
python-pyicu depends on python (>= 2.7).
python-pyicu depends on python (<< 2.8).
python-pyicu depends on python (>= 2.7).
python-pyicu depends on python (<< 2.8).
samba-common-bin depends on python.
samba depends on python (>= 2.7).
samba depends on python (<< 2.8).
samba depends on python (>= 2.7).
samba depends on python (<< 2.8).
iotop depends on python (>= 2.7.1-0ubuntu2).
iotop depends on python (<< 2.8).
iotop depends on python (>= 2.7.1-0ubuntu2).
iotop depends on python (<< 2.8).
python-cryptography depends on python (<< 2.8).
py
dpkg: error processing package python (--remove):
dependency problems - not removing
Errors were encountered while processing:
python

而且我無法再次安裝預設版本的python,因為我安裝了錯誤的版本python

$ sudo apt install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python is already the newest version (3.7.0-1).
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
iotop : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-acme : Depends: python:any (< 2.8)
              Depends: python:any (>= 2.7.5-5~)
python-asn1crypto : Depends: python:any (< 2.8)
                    Depends: python:any (>= 2.7.5-5~)
python-certifi : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-cffi-backend : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-chardet : Depends: python:any (< 2.8)
                 Depends: python:any (>= 2.7.5-5~)
python-configparser : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-crypto : Depends: python (< 2.8) but 3.7.0-1 is to be installed
                Depends: python:any (>= 2.7.5-5~)
python-cryptography : Depends: python (< 2.8) but 3.7.0-1 is to be installed
                      Depends: python:any (>= 2.7.5-5~)
python-dnspython : Depends: python:any (< 2.8)
                   Depends: python:any (>= 2.7.5-5~)
python-enum34 : Depends: python:any (< 2.8)
                Depends: python:any (>= 2.7.5-5~)
python-funcsigs : Depends: python:any (< 2.8)
                  Depends: python:any (>= 2.7.5-5~)
python-future : Depends: python:any (< 2.8)
                Depends: python:any (>= 2.7.5-5~)
python-idna : Depends: python:any (< 2.8)
              Depends: python:any (>= 2.7.5-5~)
python-ipaddress : Depends: python:any (< 2.8)
                   Depends: python:any (>= 2.7.5-5~)
python-josepy : Depends: python:any (< 2.8)
                Depends: python:any (>= 2.7.5-5~)
python-ldb : Depends: python (< 2.8) but 3.7.0-1 is to be installed
             Depends: python:any (>= 2.7.5-5~)
python-mock : Depends: python:any (< 2.8)
              Depends: python:any (>= 2.7.5-5~)
python-openssl : Depends: python:any (< 2.8)
                 Depends: python:any (>= 2.7.5-5~)
python-parsedatetime : Depends: python:any (< 2.8)
                       Depends: python:any (>= 2.7.5-5~)
python-pbr : Depends: python:any (< 2.8)
             Depends: python:any (>= 2.7.5-5~)
python-pkg-resources : Depends: python:any (< 2.8)
                       Depends: python:any (>= 2.7.5-5~)
python-pyicu : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-requests : Depends: python:any (< 2.8)
                  Depends: python:any (>= 2.7.5-5~)
python-requests-toolbelt : Depends: python:any (< 2.8)
                           Depends: python:any (>= 2.7.5-5~)
python-rfc3339 : Depends: python:any (< 2.8)
                 Depends: python:any (>= 2.7.5-5~)
python-samba : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-setuptools : Depends: python:any (< 2.8)
                    Depends: python:any (>= 2.7.5-5~)
python-six : Depends: python:any (< 2.8)
             Depends: python:any (>= 2.7.5-5~)
python-talloc : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-tdb : Depends: python (< 2.8) but 3.7.0-1 is to be installed
             Depends: python:any (>= 2.7.5-5~)
python-tz : Depends: python (< 2.8) but 3.7.0-1 is to be installed
python-urllib3 : Depends: python:any (< 2.8)
                 Depends: python:any (>= 2.7.5-5~)
samba : Depends: python (< 2.8) but 3.7.0-1 is to be installed
        Recommends: attr but it is not going to be installed
        Recommends: samba-dsdb-modules but it is not going to be installed
        Recommends: samba-vfs-modules but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

跑步讓我害怕,所以我選擇了否:

$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages will be REMOVED:
 iotop python-acme python-asn1crypto python-certifi python-cffi-backend python-chardet python-configparser python-crypto python-cryptography python-dnspython python-enum34 python-funcsigs python-future python-idna python-ipaddress
 python-josepy python-ldb python-mock python-openssl python-parsedatetime python-pbr python-pkg-resources python-pyicu python-requests python-requests-toolbelt python-rfc3339 python-samba python-setuptools python-six python-talloc
 python-tdb python-tz python-urllib3 samba samba-common-bin samba-libs
0 upgraded, 0 newly installed, 36 to remove and 0 not upgraded.
After this operation, 56.7 MB disk space will be freed.
Do you want to continue? [Y/n]

有什麼辦法可以從中恢復嗎?提前致謝!

通常apt-get dist-upgrade,通過將軟體包替換為您已啟用的實際 apt 源中的軟體包來解決此問題,但這次在您的系統上似乎沒有這樣做。

看起來您將找到一種需要重新安裝原始 Python 包的方法。

幸運的是,您可以通過指定所需的包版本來做到這一點。

但首先你必須弄清楚那個版本是什麼。為此,使用apt policy. 您應該會看到與此類似的內容:

error@vmtest-ubuntu1604:~$ sudo apt policy python
python:
 Installed: 3.7.0-1
 Candidate: 2.7.12-1~16.04
 Version table:
*** 2.7.12-1~16.04 500
       500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
       100 /var/lib/dpkg/status
    2.7.11-1 500
       500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

現在你有了它的版本號,你可以專門安裝它:

error@vmtest-ubuntu1604:~$ sudo apt install python=2.7.12-1~16.04 

-f(即使出現提示,也不要在此處使用。)

引用自:https://serverfault.com/questions/960880