mRc*_*ing 37 upgrade python3 do-release-upgrade 16.04
我想从 Ubuntu 16.04.5 LTS 升级到 18.04,所以运行sudo do-release-upgrade. 下载并解压后,bionic.tar.gz我得到:
Can not upgrade
Your python3 install is corrupted. Please fix the '/usr/bin/python3'
symlink.
Run Code Online (Sandbox Code Playgroud)
我看到了如何修复“python 安装已损坏”?所以我确实sudo ln -sf /usr/bin/python3.6 /usr/bin/python3认为这会是一个类似的问题。但这不起作用(仍然是相同的错误消息)。
我有几个python版本:
$ ls /usr/lib | grep python
python2.7
python3
python3.5
python3.6
$ update-alternatives --display python3
python3 - auto mode
link best version is /usr/bin/python3.6
link currently points to /usr/bin/python3.6
link python3 is /usr/bin/python3
/usr/bin/python3.5 - priority 1
/usr/bin/python3.6 - priority 2
Run Code Online (Sandbox Code Playgroud)
我该如何解决python3?
J. *_*ger 64
我刚刚在 Pop!_OS 18.04 上遇到了这个问题,试图升级到 18.10,结果发现问题出在符号链接 for/usr/bin/python而不是 for /usr/bin/python3。我已经/usr/bin/python3.6配置为python(not python3)的替代方案,当我更改它时,我可以do-release-upgrade按预期运行。
我希望错误消息指向python而不是python3.
之前,有问题:
$ update-alternatives --display python
python - manual mode
link best version is /usr/bin/python3.6
link currently points to /usr/bin/python2.7
link python is /usr/bin/python
/usr/bin/python2.7 - priority 1
/usr/bin/python3.6 - priority 2
Run Code Online (Sandbox Code Playgroud)
我是这样修复的:
$ sudo update-alternatives --remove-all python
$ sudo ln -sf /usr/bin/python2.7 /usr/bin/python
Run Code Online (Sandbox Code Playgroud)
另请参阅下面的评论,它描述了一个更精确的解决方案,它也更好地解释了正在发生的事情以及如何解决它。
wja*_*rea 34
您需要使用 16.04 的默认 Python 3 版本。那是3.5,而不是 3.6 。所以运行:
sudo ln -sf /usr/bin/python3.5 /usr/bin/python3
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,请尝试重新安装该python3软件包。
sudo apt-get install --reinstall python3
Run Code Online (Sandbox Code Playgroud)
顺便说一句,update-alternatives --display python3应该给你update-alternatives: error: no alternatives for python3。不同版本的 Python 在 Ubuntu 中不是替代品。
这里的答案似乎都没有解释您如何自己找到解决方案,所以我开始了一段旅程,就我而言do-release-upgrade,在 Ubuntu 18 LTS 上检查KDE Neon。
首先,我运行它tracefile -w并发现实际的 release-upgrade-scripts 下载到一个/tmp/ubuntu-release-upgrader-xxxxxxxx目录中。
grep在该目录中使用,我在DistUpgradeController.py以下位置找到了错误消息:
? grep --line-number --recursive --binary-files=without-match "python3 install is corrupted"
DistUpgradeController.py:426: _("Your python3 install is corrupted. "
Run Code Online (Sandbox Code Playgroud)
因此,我检查了使用该函数的周围代码,_pythonSymlinkCheck跳转到该代码并发现了问题的根源:脚本期望符号链接/usr/bin/python3准确解析为/usr/bin/<debian_default_python>:
binaries_and_dirnames = [("python3", "python3")]
for binary, dirname in binaries_and_dirnames:
debian_defaults = '/usr/share/%s/debian_defaults' % dirname
if os.path.exists(debian_defaults):
config = SafeConfigParser()
with open(debian_defaults) as f:
config.readfp(f)
try:
expected_default = config.get('DEFAULT', 'default-version')
except NoOptionError:
logging.debug("no default version for %s found in '%s'" %
(binary, config))
return False
try:
fs_default_version = os.readlink('/usr/bin/%s' % binary)
except OSError as e:
logging.error("os.readlink failed (%s)" % e)
return False
if not fs_default_version in (expected_default, os.path.join('/usr/bin', expected_default)):
Run Code Online (Sandbox Code Playgroud)
从脚本中可以看出,<debian_default_python>是来自以下部分的default-version关键:DEFAULT/usr/share/python3/debian_defaults
? cat /usr/share/python3/debian_defaults
[DEFAULT]
# the default python3 version
default-version = python3.6
Run Code Online (Sandbox Code Playgroud)
我的链接确实指向/usr/bin/python3.6,但通过额外的间接从update-alternatives,脚本无法解析:
? grep --line-number --recursive --binary-files=without-match "python3 install is corrupted"
DistUpgradeController.py:426: _("Your python3 install is corrupted. "
Run Code Online (Sandbox Code Playgroud)
所以最后我也决定了核选项,但现在完全了解正在发生的事情:)
sudo ln -sf /usr/bin/python3.6 /usr/bin/python
Run Code Online (Sandbox Code Playgroud)
小智 6
基本上,这个问题的解决方案包括指出/usr/bin/python您的 Ubuntu 版本所需的正确 Python 版本(例如,16.04 中是 Python2.7,18.04 中是 Python3.6)。
如果您的系统中安装了多个版本的 Python,您可能会使用update-alternatives它们来管理它们。你的默认 Python 替代版本是否是你的系统所需的正确版本(Ubuntu 18.04 中的 3.6)并不重要,它不会工作。
这不起作用的原因是,当使用update-alternatives,/usr/bin/python3指向 时,这似乎与指向/etc/alternatives/python3不完全相同。/usr/bin/python3/usr/bin/python3.6
这就是为什么此问题的解决方案通常包括停止管理您的 Python3 版本并update-alternatives指向/usr/bin/python3您的系统所需的正确的 Python3 版本。
当我想从16.04 LTS升级到18.04 LTS时,我在运行 WSL Ubuntu 的 Windows 10 1903 上观察到此错误消息。
之后do-release-upgrade失败了,我改用python替代品所提供的每一个选择update-alternatives --config python,并再次运行升级命令。那没有帮助。
然后我检查了/var/log/dist-upgrade/main.log包含这些行的日志文件
2019-09-02 20:58:08,686 DEBUG _pythonSymlinkCheck run
2019-09-02 20:58:08,687 DEBUG python symlink points to: '/etc/alternatives/python', but expected is 'python2.7' or
'/usr/bin/python2.7'
2019-09-02 20:58:08,688 ERROR pythonSymlinkCheck() failed, aborting
Run Code Online (Sandbox Code Playgroud)
因此,尽管错误消息提到了python3,但问题是关于python2 的。
升级脚本检查/usr/bin/python链接到/usr/bin/python2,请参阅DistUpgrade/DistUpgradeController.py此处的源代码:ubuntu launchpad
因此,一种解决方案是从替代系统中完全删除 python 并手动添加链接,如最流行的答案中所述。
如果不想从替代系统中删除python,只需在升级过程中更改链接即可:
# rm /usr/bin/python
# ln -sf /usr/bin/python2.7 /usr/bin/python
# do-release-upgrade
Run Code Online (Sandbox Code Playgroud)
这对我有用。
升级过程中,链路自动修复。所以当升级完成后,它指向了alternatives目录下的python入口:
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Sep 2 22:01 /usr/bin/python -> /etc/alternatives/python
Run Code Online (Sandbox Code Playgroud)
编辑:有关详细信息,如果您从 18.04 LTS 升级到 19.04 并且 anwser 也适用于这种情况,也可能会出现该问题。
| 归档时间: |
|
| 查看次数: |
34940 次 |
| 最近记录: |