Python ImportError:没有名为distutils的模块
尝试安装Python ImportError:没有名为distutils的模块,python,distutils,easy-install,Python,Distutils,Easy Install,尝试安装psutils导致了一个大麻烦 $ python -V Python 2.4.2 $ cat /etc/SuSE-release SUSE Linux Enterprise Server 10 (x86_64) VERSION = 10 PATCHLEVEL = 4 $ cd psutil-2.1.1/ $ python setup.py install Traceback (most recent call last): File "setup.py", line 17, i
psutils
导致了一个大麻烦
$ python -V
Python 2.4.2
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
$ cd psutil-2.1.1/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 17, in ?
from distutils.core import setup, Extension
ImportError: No module named distutils.core
下一步-我尝试安装setuptools
以使用easy\u install
:
$ which easy_install
which: no easy_install
$ cd ../setuptools-1.4/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 12, in ?
from distutils.util import convert_path
ImportError: No module named distutils.util
正在尝试从ez_setup.py
安装distutils
:
$ python ez_setup.py
Traceback (most recent call last):
File "ez_setup.py", line 278, in ?
main(sys.argv[1:])
File "ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "ez_setup.py", line 139, in download_setuptools
from distutils import log
ImportError: No module named distutils
那么-我如何安装它
注意:不,我没有此计算机的root用户,无法使用软件包管理器。您需要运行此程序(如果python3上发生错误)==>sudo apt get install python3 distutils--重新安装
您需要运行此命令(如果python2上发生错误)==>sudo apt get install python2 distutils——重新安装
我有一个答案,但我会复制到这里
AskUbuntu回答:
Debian已经决定distutils不是一个核心python包,因此它不包括在Debian和基于Debian的操作系统的最后版本中。您应该能够执行sudo-apt-install python3-distutils
,它应该可以工作
然而,这对我来说并不管用。我使用Parrot操作系统,它和Ubuntu一样,基于Debian。我升级了我的系统,pip停止了python3.7的工作,并且我还得到了错误
ModuleNotFoundError:没有名为'distutils.util'的模块
我尝试了很多东西来修复它并重新安装distutils,我发现纯粹是运气使然,python3.8的pip3确实起了作用。然后我尝试了python3.7-mpip3-V
,得到了/usr/bin/python3.7:没有名为pip3的模块,所以我决定查看/usr/lib
文件
我查看了/usr/lib/python3/dist包,一切看起来都很好。然后我查看了/usr/lib/python3.7
,看到了文件夹distutil
我打开它,看到了\uuuupycache\uuuuuuu
,\uuuuuu init\uuuuuuuuupy
文件和version.py
文件。我不知道应该有多少文件,或者代码应该是什么,但我知道这两个文件要么是错误的,要么是缺少另一个文件
然后我看了一下/usr/lib/python3.8/distutil中的内容,它完全不同。我找到了以下文件:
command Folder
__pycache__ Folder
archive_util.py Python script
bcppcompiler.py Python script
cmd.py Python script
config.py Python script
core.py Python script
cygwinccompiler.py Python script
debug.py Python script
dep_util.py Python script
errors.py Python script
extension.py Python script
fancy_getopt.py Python script
filelist.py Python script
file_util.py Python script
__init__.py Python script
log.py Python script
msvc9compiler.py Python script
_msvccompiler.py Python script
msvccompiler.py Python script
README Plain text file
spawn.py Python script
sysconfig.py Python script
text_file.py Python script
unixccompiler.py Python script
util.py Python script
version.py Python script
versionpredicate.py Python script
这更有希望,因为pip3确实起作用,所以我认为这个distutils也起作用,我试图通过运行以下命令将其复制到python3.7文件夹:
sudo cp-r/usr/lib/python3.8/distutil/usr/lib/python3.7/distutil
然后我再次尝试了python3.7-mpip-V
,得到了
PIP20.0.2来自/usr/lib/python3/dist-packages/pip(python 3.7)
然后我试着安装了一些模块,一切正常。
我希望这会有帮助。@ciro
我需要做更多的工作才能让virtualenv再次运行(从18.04升级到20.04):
你有没有想过让你的root用户更新Python到2.7?这是不可能的,不幸的是…顺便说一句,CentOS 6.4上的默认值也是2.4。。。2.4没有内置的distutils?或者distutils自从2.4I总是在这样一个盒子上安装一个单独的Python2.7以来发生了变化。在2.4上仍然有效的软件包很少。对我来说不起作用
sudo cp /usr/lib/python3.8/_sysconfigdata__* /usr/lib/python3.6/
cd /usr/lib/python3.6
sudo ln -s _sysconfigdata_m_linux_x86_64-linux-gnu.py _sysconfigdata_m_x86_64-linux-gnu.py