Sau*_*mar 6 upgrade python apt python-2.7 16.04
一切都很顺利,直到今天我决定将 Ubuntu 16.04.3升级到16.04.4
在安装下载的更新的最后阶段时,python-minimal打包安装失败并出现以下错误:
Setting up python-minimal (2.7.12-1~16.04) ...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/compileall.py", line 16, in <module>
import struct
File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
from _struct import *
ImportError: No module named _struct
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)
我认为重新安装 python 和适当的软件包会有所帮助。但不幸的是,我最终卸载了所有依赖于 python 的 python 包和软件,如 gimp、mplayer、kde、kicad、pycharm 等。
现在,每次我尝试安装 python 时,都会出现以下错误:
$ sudo apt-get install python
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python-minimal python2.7 python2.7-minimal
Suggested packages:
python-doc python-tk python2.7-doc
The following NEW packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-minimal python2.7 python2.7-minimal
0 upgraded, 7 newly installed, 0 to remove and 21 not upgraded.
Need to get 1,628 kB/3,877 kB of archives.
After this operation, 16.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython2.7-minimal amd64 2.7.12-1ubuntu0~16.04.3 [340 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python2.7-minimal amd64 2.7.12-1ubuntu0~16.04.3 [1,261 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python-minimal amd64 2.7.12-1~16.04 [28.1 kB]
Fetched 1,628 kB in 6s (248 kB/s)
Selecting previously unselected package libpython2.7-minimal:amd64.
(Reading database ... 250996 files and directories currently installed.)
Preparing to unpack .../libpython2.7-minimal_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../python2.7-minimal_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking python2.7-minimal (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python-minimal.
Preparing to unpack .../python-minimal_2.7.12-1~16.04_amd64.deb ...
Unpacking python-minimal (2.7.12-1~16.04) ...
Selecting previously unselected package libpython2.7-stdlib:amd64.
Preparing to unpack .../libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../python2.7_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking python2.7 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package libpython-stdlib:amd64.
Preparing to unpack .../libpython-stdlib_2.7.12-1~16.04_amd64.deb ...
Unpacking libpython-stdlib:amd64 (2.7.12-1~16.04) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20180209-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Setting up python2.7-minimal (2.7.12-1ubuntu0~16.04.3) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python-minimal (2.7.12-1~16.04) ...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/compileall.py", line 16, in <module>
import struct
File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
from _struct import *
ImportError: No module named _struct
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)
我也无法安装任何需要 python 的软件。
升级失败后我当前的 ubuntu 版本:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过类似的问题并且能够解决它?任何帮助将不胜感激。
经过数小时的努力和数百次安装/卸载 python 包,看起来我能够安装 python 包,包括python-minimal. 让我分享我的成功故事。
一开始,我什至无法卸载 python-minimal。每次安装/卸载时都会显示我在问题中提到的错误。甚至尝试过,sudo apt-get -f install但没有任何收获。不知何故,我发现它只能与其他几个软件包一起卸载。以下命令,我用来完成删除python-minimal损坏和残留的包:
sudo apt-get autoremove libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python-minimal python2.7 python2.7-minimal
Run Code Online (Sandbox Code Playgroud)
这将删除所有 python 包和依赖 python 的软件。我知道这很极端,但相信我,我别无选择。
sudo apt-get remove --purge $(sudo dpkg -l | egrep "^(rc|iU)" | awk '{print $2}' | tr '\n' ' ')
Run Code Online (Sandbox Code Playgroud)
去除剩余的残留和破损的包裹(如果有)。
注意:我复制了在此步骤中删除的软件包列表。我知道我会再次需要它!
接下来我搜索了所有安装 python2.7 的地方并删除了默认 python 的所有文件和目录。我希望我不必手动删除它们,但别无选择:
sudo find / -iname python2.7
/etc/python2.7
/usr/local/bin/python2.7
/usr/local/lib/python2.7
/usr/lib/python2.7
/usr/bin/python2.7.13/lib/python2.7
/usr/bin/python2.7.13/bin/python2.7
/usr/bin/python2.7.13/include/python2.7
/usr/bin/python2.7
/usr/include/x86_64-linux-gnu/python2.7
/usr/include/python2.7
/usr/share/doc/python2.7
/usr/share/binfmts/python2.7
/usr/share/lintian/overrides/python2.7
/proc/sys/fs/binfmt_misc/python2.7
/var/lib/binfmts/python2.7
Run Code Online (Sandbox Code Playgroud)
我不必删除上面列出的所有文件/目录,只删除了默认版本:
sudo rm -rf /etc/python2.7 /usr/local/bin/python2.7 /usr/local/lib/python2.7 /usr/lib/python2.7
Run Code Online (Sandbox Code Playgroud)
还有其他版本的python,并没有造成任何麻烦。我相信搜索可能因用户而异,并且whereis python可以使用命令来获取安装的默认 python 的路径。
接下来,我成功安装了python:
sudo apt-get install python
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python-minimal python2.7 python2.7-minimal
Suggested packages:
python-doc python-tk python2.7-doc
The following NEW packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-minimal python2.7 python2.7-minimal
0 upgraded, 7 newly installed, 0 to remove and 21 not upgraded.
Need to get 0 B/3,877 kB of archives.
After this operation, 16.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package libpython2.7-minimal:amd64.
(Reading database ... 250996 files and directories currently installed.)
Preparing to unpack .../libpython2.7-minimal_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../python2.7-minimal_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking python2.7-minimal (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python-minimal.
Preparing to unpack .../python-minimal_2.7.12-1~16.04_amd64.deb ...
Unpacking python-minimal (2.7.12-1~16.04) ...
Selecting previously unselected package libpython2.7-stdlib:amd64.
Preparing to unpack .../libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../python2.7_2.7.12-1ubuntu0~16.04.3_amd64.deb ...
Unpacking python2.7 (2.7.12-1ubuntu0~16.04.3) ...
Selecting previously unselected package libpython-stdlib:amd64.
Preparing to unpack .../libpython-stdlib_2.7.12-1~16.04_amd64.deb ...
Unpacking libpython-stdlib:amd64 (2.7.12-1~16.04) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20180209-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Setting up python2.7-minimal (2.7.12-1ubuntu0~16.04.3) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python-minimal (2.7.12-1~16.04) ...
Selecting previously unselected package python.
(Reading database ... 251742 files and directories currently installed.)
Preparing to unpack .../python_2.7.12-1~16.04_amd64.deb ...
Unpacking python (2.7.12-1~16.04) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Processing triggers for man-db (2.7.5-1) ...
Setting up libpython2.7-stdlib:amd64 (2.7.12-1ubuntu0~16.04.3) ...
Setting up python2.7 (2.7.12-1ubuntu0~16.04.3) ...
Setting up libpython-stdlib:amd64 (2.7.12-1~16.04) ...
Setting up python (2.7.12-1~16.04) ...
Run Code Online (Sandbox Code Playgroud)
注意:这仅安装了非常必要和最少的 python 包。您可能仍然需要安装在第一步中卸载的所有其他 python 包。
一些额外的注意事项:
第 2 步删除了使用pip全局安装的第 3 方 python 包。不幸的是,我没有列出清单,最终我的项目需要它们时遇到了一些麻烦。但这没什么大不了的,因为我所有的项目都有自己的 python requirements.txt 文件。但我仍然建议你们在开始第一步之前将 python 包保存在一个文件中。以下命令可以派上用场:
pip freeze > python_pip_packages.txt
Run Code Online (Sandbox Code Playgroud)
我还必须删除 pip 文件和目录(类似于我删除 python 默认文件和目录的方式)并重新安装 pip:
sudo apt-get install python-pip # installing pip
sudo pip install --upgrade pip # upgrading pip to latest version using pip itself
sudo pip install -r python_pip_packages.txt # re-installing all 3rd party python packages which were removed in 2nd step.
Run Code Online (Sandbox Code Playgroud)
希望其他人不要像我一样受苦:)
小智 5
对于那些在运行命令时不断陷入困境的人(它不断抱怨 python 或任何其他包),我经历了同样的事情,并通过删除以下信息来解决这个问题
/var/lib/dpkg/info/<the package giving you headache>
Run Code Online (Sandbox Code Playgroud)
之后,应该允许您继续安装/升级/更新
| 归档时间: |
|
| 查看次数: |
13857 次 |
| 最近记录: |