更新 20.04 时出现问题 - python3.7 错误

更新 20.04 时出现问题 - python3.7 错误

我正在尝试运行正常更新/升级并收到此错误:

dpkg: warning: files list file for package 'libpython3.7-minimal:amd64' missing; assuming package has no files currently installed
(Reading database ... 141307 files and directories currently installed.)
Preparing to unpack .../libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb ...
Unpacking libpython3.7-stdlib:amd64 (3.7.13-1+focal3) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.7/distutils/__init__.py', which is also in package python3.7-distutils 3.7.13-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试过谷歌搜索并查看这里,但最近找到的解决方案不起作用。尝试运行 Broken Fix 会导致:

dpkg: error processing archive /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.7/distutils/__init__.py', which is also in package python3.7-distutils 3.7.13-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

我通过删除 python3.7 及其库然后重新安装来修复它。

这对我有用:

sudo dpkg --remove --force-remove-reinstreq python3.7 
sudo dpkg --remove --force-remove-reinstreq libpython3.7-stdlib 
sudo apt-get clean 
sudo apt-get autoremove 
sudo apt-get install python3.7

答案2

以前的答案都不适合我,所以我决定使用:

sudo apt-get remove --purge *python3.7*
sudo apt-get clean
sudo apt-get install python3.7-full

这是在使用存储库中的 Python 的背景下的deadsnakes

答案3

删除并重新安装 python 3.7 对我来说有效

sudo dpkg --remove --force-remove-reinstreq python3.7 
sudo dpkg --remove --force-remove-reinstreq libpython3.7-stdlib 
sudo apt-get clean 
sudo apt-get autoremove 
sudo apt-get install python3.7

答案4

对于非管理用途,最好使用 Anaconda/Miniconda。您也可以从主文件夹中的源代码编译 python。

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar -xf Python-2.7.18.tgz

cd Python-2.7.18/

./configure --enable-optimizations --enable-shared --prefix=$HOME/local
 make -j4
 make install

要使用此安装,请将这些行添加到 $HOME/.bashrc 并将其作为源。

export PATH=$HOME/local/bin
export LD_LIBRARY_PATH=$HOME/local/lib
export MANPATH=$HOME/local/share/man

由于不同的项目经常使用冲突的软件包,您可以使用不同的 conda 环境或在本地安装中使用 venv

python -m venv <project_name>_env

这将激活此环境使用

. <project_name>_env/bin/activate

deactivate

出来。

相关内容