我正在尝试安装 virtualenv,但在 ubuntu bionic 上出现以下错误
rock64@rockpro64:~$ pip3 install virtualenv virtualenvwrapper
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
ImportError: cannot import name 'sysconfig
'但是如果我尝试安装 distutils 我会得到不同的错误:
rock64@rockpro64:~$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
python3-distutils python3-lib2to3
The following NEW packages will be installed:
python3-distutils python3-lib2to3
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/222 kB of archives.
After this operation, 3,143 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 120131 files and directories currently installed.)
Preparing to unpack .../python3-lib2to3_3.6.9-1~18.04_all.deb ...
Unpacking python3-lib2to3 (3.6.9-1~18.04) ...
dpkg: error processing archive /var/cache/apt/archives/python3-lib2to3_3.6.9-1~18.04_all.deb (--unpack):
trying to overwrite '/usr/lib/python3.8/lib2to3/Grammar.txt', which is also in package python3.8-lib2to3 3.8.0-1+bionic2
Preparing to unpack .../python3-distutils_3.6.9-1~18.04_all.deb ...
Unpacking python3-distutils (3.6.9-1~18.04) ...
dpkg: error processing archive /var/cache/apt/archives/python3-distutils_3.6.9-1~18.04_all.deb (--unpack):
trying to overwrite '/usr/lib/python3.8/distutils/README', which is also in package python3.8-distutils 3.8.0-1+bionic2
Errors were encountered while processing:
/var/cache/apt/archives/python3-lib2to3_3.6.9-1~18.04_all.deb
/var/cache/apt/archives/python3-distutils_3.6.9-1~18.04_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
根据此更改日志通知适用于其 Python 3.8 版本的最新版本,Deadsnakes PPA 的维护者承认他们的版本与上游 Ubuntu 冲突。
首先更新python3.8
到最新版本或完全删除它。您需要确保删除python3.8-distutils
、python3.8-tk
、python3.8-gdbm
、python3.8-lib2to3
软件包,之后您应该不再与 Ubuntu 软件包发生冲突。
然后您应该能够python3-distutils
从官方 Ubuntu 存储库进行安装,这应该可以解决virtualenv
您遇到的问题。