我正在尝试安装 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)
根据最新版本的 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
您遇到的问题。