Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named distutils

Attempt to install psutils resulted a big headache...

$ 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:

$ 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:

$ 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?

P.S. No, I haven't root on this machine and can't use package manager.

like image 563
setevoy Avatar asked May 13 '14 08:05

setevoy


2 Answers

you need to run this (if Error happens on 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

like image 109
steveoams Avatar answered Oct 14 '22 22:10

steveoams


I have an answer here but I will copy it here

AskUbuntu answer:

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. You should be able to do sudo apt install python3-distutils and it should work.

However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error 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. 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.

I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.

I opened it, and saw the __pycache__, the __init__.py file and a version.py file. 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. 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:

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

Then I tried again python3.7 -m pip -V and got

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.

like image 34
Ciro García Avatar answered Oct 14 '22 22:10

Ciro García