今日闲的蛋疼,想要升级一下ubuntu16.04服务器上的python版本(现在装的是python3.5,但心血来潮想装python3.10体验一下),结果引发了一连串血案。
- python3.10的安装:
- 添加ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
,执行后回车等一会; sudo apt update
sudo apt install python3.10
- 添加ppa:
- python3.10的问题及卸载:
- pip的时候出问题:
AttributeError: module 'collections' has no attribute 'MutableMapping'
,参考了 https://github.com/sabnzbd/sabnzbd/issues/1971 的python3.10 -m pip install babelfish -U
,但是pip install
就执行不了,所以不行; - 尝试删除,千万不要这样做!!!! 用了 https://blog.csdn.net/p1279030826/article/details/116564195 的
sudo apt-get purge --auto-remove python3.10
,还确认了。千万不要这样做!!!!。都是因为直接执行apt remove python3.10之后还能用python3.10。(实际上,直接remove python3.10-minimal就能解决这个问题)。关于autoremove的说明在 https://blog.csdn.net/x2222265/article/details/88526690 有; - 后来又尝试安装python3.9,但是python3.9的pip仍然不可用。
- pip的时候出问题:
- apt出问题:
- 继续手欠,尝试了apt的update和upgrade,发现出了一个大问题:依赖出现问题,并且提示让我使用
apt -f install
命令。但使用该命令后仍然有各种依赖冲突,并且提示:E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
和E: Unable to correct dependencies
,就像 https://superuser.com/questions/1386209/how-to-solve-this-dependencies-apt-fix-broken-install 所说;并且自动升级到了python3.6,python3.6中会出现python3 ModuleNotFoundError: No module named 'typing'
问题。 - 解决方案:
- https://blog.csdn.net/weixin_42156097/article/details/103805063 给出用aptitude安装,但是并没有aptitude并且安装aptitude的时候仍是报之前的错;
- https://askubuntu.com/questions/124845/eerror-pkgproblemresolverresolve-generated-breaks-this-may-be-caused-by-hel 给出用update和upgrade,但是仍没有效果,upgrade的时候报之前的错误;
- https://stackoverflow.com/questions/30768828/e-error-pkgproblemresolverresolve-generated-breaks-this-may-be-caused-by-he 给出
sudo dpkg --configure -a
,并且新开一个ssh链接,执行update和upgrade有效。这个过程中仍有一些问题,如下所示:- 问题1:https://askubuntu.com/questions/148383/how-to-resolve-dpkg-error-processing-var-cache-apt-archives-python-apport-2-0 出现类似
dpkg: error processing /var/cache/apt/archives/python-apport_2.0.1-0ubuntu9_all.deb
的提示。解决:用sudo dpkg -i --force-overwrite <filename>
- 问题2:在dpkg执行过程中,要删除一个东西的时候出现
python3 ModuleNotFoundError: No module named 'typing'
。问题是在于:这里用到了python,但python用的是后来装的python版本,所以直接重新链接python(将/usr/lib/python3
换成python3.5)- 提示全文:
dell@slave1:~$ sudo apt-get -f install Reading package lists... Done Building dependency tree Reading state information... Done Correcting dependencies... Done The following packages were automatically installed and are no longer required: distro-info libllvm4.0 libllvm5.0 libpython3-dev libpython3.5-dev libpython3.9-minimal libqt5x11extras5 python3-distro-info python3-yaml python3.5-dev python3.9-minimal qml-module-qtquick-controls qml-module-qtquick-dialogs qml-module-qtquick-privatewidgets qtdeclarative5-controls-plugin qtdeclarative5-dialogs-plugin Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libnettle6 libpython3.6-stdlib The following packages will be REMOVED: ubuntu-advantage-tools The following NEW packages will be installed: libnettle6 libpython3.6-stdlib 0 upgraded, 2 newly installed, 1 to remove and 0 not upgraded. 2 not fully installed or removed. Need to get 0 B/2,313 kB of archives. After this operation, 7,973 kB of additional disk space will be used. Do you want to continue? [Y/n] Y (Reading database ... 307863 files and directories currently installed.) Removing ubuntu-advantage-tools (27.4.1~16.04.1) ... Traceback (most recent call last): File "<string>", line 2, in <module> File "/usr/lib/python3/dist-packages/uaclient/apt.py", line 7, in <module> from typing import Dict, List, Optional ModuleNotFoundError: No module named 'typing' dpkg: error processing package ubuntu-advantage-tools (--remove): subprocess installed pre-removal script returned error exit status 1 Errors were encountered while processing: ubuntu-advantage-tools E: Sub-process /usr/bin/dpkg returned an error code (1) ```
- 问题1:https://askubuntu.com/questions/148383/how-to-resolve-dpkg-error-processing-var-cache-apt-archives-python-apport-2-0 出现类似
- 继续手欠,尝试了apt的update和upgrade,发现出了一个大问题:依赖出现问题,并且提示让我使用
- python升级到3.6的后遗症
- 之前upgrade安装了python3.6,但是pip还是之前的python3.9的pip。所以删掉
/usr/local/bin/pip
并通过sudo cp /usr/local/bin/pip3.6 /usr/local/bin/pip
将pip重新指定定了一次; - 用pip的时候出现
ImportError: cannot import name 'sysconfig' from 'distutils'
,所以用 https://www.codeleading.com/article/11985788299/ 的方法,利用sudo apt-get install python3.6-distutils
修复。
- 之前upgrade安装了python3.6,但是pip还是之前的python3.9的pip。所以删掉