Python3
安裝 virtualenvwrapper 和 distutils 時出錯
我正在嘗試安裝 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
您遇到的問題。