使用python2.7安装和卸载软件包

使用python2.7安装和卸载软件包

我在 ubuntu-18.04lts 上安装和删除包时遇到了问题。

首先,我对 python -2.7 有问题

$ python
Traceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 554, in <module>
    main()
  File "/usr/lib/python2.7/site.py", line 536, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python2.7/site.py", line 272, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/lib/python2.7/site.py", line 247, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/lib/python2.7/site.py", line 237, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/lib/python2.7/sysconfig.py", line 587, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 533, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 417, in _init_posix
    from _sysconfigdata import build_time_vars
  File "/usr/lib/python2.7/_sysconfigdata.py", line 6, in <module>
ImportError: No module named _sysconfigdata_nd
$ sudo apt purge -y python2.7-minimal
$ sudo apt-get clean
$ sudo apt-get update

$ sudo dpkg --configure -a
Setting up python-idna (2.6-1) ...
/var/lib/dpkg/info/python-idna.postinst: 6: /var/lib/dpkg/info/python-idna.postinst: pycompile: not found
dpkg: error processing package python-idna (--configure):
 installed python-idna package post-installation script subprocess returned error exit status 127
Setting up python-asn1crypto (0.24.0-1) ...
/var/lib/dpkg/info/python-asn1crypto.postinst: 6: /var/lib/dpkg/info/python-asn1crypto.postinst: pycompile: not found
dpkg: error processing package python-asn1crypto (--configure):
 installed python-asn1crypto package post-installation script subprocess returned error exit status 127
Setting up python-wheel (0.30.0-0.2) ...
/var/lib/dpkg/info/python-wheel.postinst: 6: /var/lib/dpkg/info/python-wheel.postinst: pycompile: not found
dpkg: error processing package python-wheel (--configure):
 installed python-wheel package post-installation script subprocess returned error exit status 127
Setting up python2.7 (2.7.17-1~18.04ubuntu1.7) ...
/var/lib/dpkg/info/python2.7.postinst: 9: /var/lib/dpkg/info/python2.7.postinst: /usr/bin/python2.7: not found
dpkg: error processing package python2.7 (--configure):
 installed python2.7 package post-installation script subprocess returned error exit status 127
Setting up python-pkg-resources (39.0.1-2) ...
/var/lib/dpkg/info/python-pkg-resources.postinst: 6: /var/lib/dpkg/info/python-pkg-resources.postinst: pycompile: not found
dpkg: error processing package python-pkg-resources (--configure):
 installed python-pkg-resources package post-installation script subprocess returned error exit status 127
Setting up python-gi (3.26.1-2ubuntu1) ...
/var/lib/dpkg/info/python-gi.postinst: 6: /var/lib/dpkg/info/python-gi.postinst: pycompile: not found
dpkg: error processing package python-gi (--configure):
 installed python-gi package post-installation script subprocess returned error exit status 127
Setting up python-six (1.11.0-2) ...
/var/lib/dpkg/info/python-six.postinst: 6: /var/lib/dpkg/info/python-six.postinst: pycompile: not found
dpkg: error processing package python-six (--configure):
 installed python-six package post-installation script subprocess returned error exit status 127
Setting up python-enum34 (1.1.6-2) ...
/var/lib/dpkg/info/python-enum34.postinst: 6: /var/lib/dpkg/info/python-enum34.postinst: pycompile: not found
dpkg: error processing package python-enum34 (--configure):
 installed python-enum34 package post-installation script subprocess returned error exit status 127
dpkg: error processing package apport (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Setting up python-dbus (1.2.6-1) ...
/var/lib/dpkg/info/python-dbus.postinst: 6: /var/lib/dpkg/info/python-dbus.postinst: pycompile: not found
dpkg: error processing package python-dbus (--configure):
 installed python-dbus package post-installation script subprocess returned error exit status 127
Setting up python-ipaddress (1.0.17-1) ...
/var/lib/dpkg/info/python-ipaddress.postinst: 6: /var/lib/dpkg/info/python-ipaddress.postinst: pycompile: not found
dpkg: error processing package python-ipaddress (--configure):
 installed python-ipaddress package post-installation script subprocess returned error exit status 127
Setting up python-pip (9.0.1-2.3~ubuntu1.18.04.5) ...
/var/lib/dpkg/info/python-pip.postinst: 6: /var/lib/dpkg/info/python-pip.postinst: pycompile: not found
dpkg: error processing package python-pip (--configure):
 installed python-pip package post-installation script subprocess returned error exit status 127
Setting up python-xdg (0.25-4ubuntu1.1) ...
/var/lib/dpkg/info/python-xdg.postinst: 6: /var/lib/dpkg/info/python-xdg.postinst: pycompile: not found
dpkg: error processing package python-xdg (--configure):
 installed python-xdg package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of apport-gtk:
 apport-gtk depends on apport (>= 0.41); however:
  Package apport is not configured yet.

dpkg: error processing package apport-gtk (--configure):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
Errors were encountered while processing:
 python-idna
 python-asn1crypto
 python-wheel
 python2.7
 python-pkg-resources
 python-gi
 python-six
 python-enum34
 apport
 python-dbus
 python-ipaddress
 python-pip
 python-xdg
 apport-gtk
$ sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apport
The following packages will be upgraded:
  apport
1 upgraded, 0 newly installed, 0 to remove and 52 not upgraded.
14 not fully installed or removed.
Need to get 126 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://65.66.67.68/ubuntu bionic-updates/main amd64 apport all 2.20.9-0ubuntu7.28 [126 kB]
Fetched 126 kB in 0s (2,193 kB/s)
dpkg: warning: files list file for package 'dpkg-dev' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'dpkg' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'python2.7-minimal' missing; assuming package has no files currently installed
(Reading database ... 259674 files and directories currently installed.)
Preparing to unpack .../apport_2.20.9-0ubuntu7.28_all.deb ...
/var/lib/dpkg/info/apport.prerm: 22: /var/lib/dpkg/info/apport.prerm: pyclean: not found
dpkg: warning: old apport package pre-removal script subprocess returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 22: /var/lib/dpkg/tmp.ci/prerm: pyclean: not found
dpkg: error processing archive /var/cache/apt/archives/apport_2.20.9-0ubuntu7.28_all.deb (--unpack):
 new apport package pre-removal script subprocess returned error exit status 127
/var/lib/dpkg/info/apport.postinst: 13: /var/lib/dpkg/info/apport.postinst: pycompile: not found
dpkg: error while cleaning up:
 installed apport package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 /var/cache/apt/archives/apport_2.20.9-0ubuntu7.28_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

包裹似乎已损坏。任何帮助解决此问题的方法都会有所帮助。

答案1

这 ...

$ apt-file 查找 _sysconfigdata_nd
libpython2.7-最小:/usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py

$ apt-rdepends libpython2.7-minimal
正在读取软件包列表...完成
构建依赖关系树       
正在读取状态信息...完成
libpython2.7-最低

...表示你以某种方式弄乱了python,甚至卸载了系统版本的python。
注意:此版本的 python 是“apt”和“apt-get”等的核心。

从 ubuntu 服务器下载 *.deb 文件 (libpython2.7-minimal) 并执行
$ sudo dpkg -i <filename>
(文件名可能与包名略有不同,例如告知版本)

相关内容