简体   繁体   English

导入错误:没有名为 distutils 的模块

[英]ImportError: No module named distutils

Attempt to install psutils resulted a big headache...尝试安装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

Next - I try to install setuptools to use easy_install :接下来 - 我尝试安装setuptools以使用easy_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

Trying install distutils from ez_setup.py :尝试从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

So - how can I install it?那么 - 我该如何安装它?

PS No, I haven't root on this machine and can't use package manager. PS 不,我在这台机器上没有 root,不能使用包管理器。

you need to run this (if Error happens on python3) ==> sudo apt-get install python3-distutils --reinstall你需要运行这个(如果错误发生在 python3 上)==> sudo apt-get install python3-distutils --reinstall

you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall你需要运行这个(如果错误发生在 python2 上)==> sudo apt-get install python2-distutils --reinstall

I have an answer here but I will copy it here我在这里有答案但我会在这里复制

AskUbuntu answer: AskUbuntu 回答:

Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. Debian 已决定 distutils 不是核心 python 包,因此它不包含在 debian 和基于 debian 的操作系统的最新版本中。 You should be able to do sudo apt install python3-distutils and it should work.您应该能够执行sudo apt install python3-distutils并且它应该可以工作。

However, it did not work for me.但是,它对我不起作用。 I use Parrot OS, which is, as Ubuntu, Debian based.我使用 Parrot OS,它是基于 Ubuntu 的 Debian。 I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'我升级了我的系统,pip 停止为 python3.7 工作,我也收到了错误ModuleNotFoundError: No module named 'distutils.util'

I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work.我尝试了很多方法来修复它并重新安装 distutils,我纯粹是靠运气发现 pip3,python3.8确实有效。 I then tried python3.7 -m pip3 -V , got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.然后我尝试了python3.7 -m pip3 -V ,得到了/usr/bin/python3.7: No module named pip3所以我决定看看/usr/lib文件。

I looked at /usr/lib/python3/dist-packages and everything looked fine.我查看了/usr/lib/python3/dist-packages ,一切看起来都很好。 Then I looked at /usr/lib/python3.7 and saw the folder distutil .然后我查看了/usr/lib/python3.7并看到了文件夹distutil

I opened it, and saw the __pycache__ , the __init__.py file and a version.py file.我打开它,看到了__pycache____init__.py文件和一个version.py文件。 I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.我不知道里面应该有多少文件,或者代码应该是什么,但我知道这两个文件要么是错误的,要么是缺少另一个文件。

Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different.然后我查看了/usr/lib/python3.8/distutil里面的内容,它完全不同。 I found the following files:我找到了以下文件:

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

This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:这更有希望,因为 pip3 确实有效,我认为这个 distutils 也有效,我尝试通过运行以下命令将其复制到 python3.7 文件夹:

sudo cp -r /usr/lib/python3.8/distutil /usr/lib/python3.7/distutil

Then I tried again python3.7 -m pip -V and got然后我再次尝试python3.7 -m pip -V并得到

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)

Then I tried installing some modules and everything works fine.然后我尝试安装一些模块,一切正常。 I hope this is helpful.我希望这是有帮助的。

@ciro @ciro

I need to do even more to get virtualenv running again (upgraded from 18.04 to 20.04):我需要做更多的事情才能让 virtualenv 再次运行(从 18.04 升级到 20.04):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入错误:pandas pyinstaller 中没有名为“distutils”的模块 - ImportError: No module named 'distutils' in pandas pyinstaller 导入错误:没有名为 Cython.Distutils 的模块 - ImportError: No module named Cython.Distutils ImportError:没有名为numpy.distutils.core的模块(在安装keras期间) - ImportError: No module named numpy.distutils.core (during keras installation) ImportError:没有名为numpy.distutils.core的模块(Ubuntu xgboost安装) - ImportError: No module named numpy.distutils.core (Ubuntu xgboost installation) ImportError:在 Windows/Python 中安装 XGBoost 时没有名为 numpy.distutils.core 的模块 - ImportError: No module named numpy.distutils.core while installing XGBoost in Windows/Python Windows:ModuleNotFoundError:没有名为“ distutils”的模块 - Windows: ModuleNotFoundError: No module named 'distutils' ModuleNotFoundError:没有名为“setuptools._distutils”的模块 - ModuleNotFoundError: No module named 'setuptools._distutils' ModuleNotFoundError:没有名为“distutils.core”的模块 - ModuleNotFoundError: No module named 'distutils.core' ModuleNotFoundError:没有名为“_distutils_hack”的模块 - ModuleNotFoundError: No module named '_distutils_hack' ImportError:没有名为'twisted'的模块 - ImportError: No module named 'twisted'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM